Vim: Undo reselects previous change
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
The Undo action in vim mode is the exact same as Zed's default mode, it reselects the text you had selected on your previous change.
This differs from Neovim's behaviour of only moving the cursor at the start of the previously selected range.
Pressing u more than once using a build that contains this change #6948 will:
- Undo your change but reselect it
- Lowercase the now selected text
- Undo the lowercasing
- Repeat steps 2 and 3 ad infinitum
Steps to reproduce it
Use a recent version of Zed
- Enter insert mode with
i - Type
HELLOthenEscape - Press
viwdto select what you just typed and then delete it - Keeping pressing
u
Expected behaviour: the text to be gone after two u presses.
https://github.com/zed-industries/zed/assets/63453504/2f760edb-00b0-4201-8976-4298cc6822d0
Actual behaviour: the text keeps switching between HELLO and hello.
https://github.com/zed-industries/zed/assets/63453504/d79e96df-1ac4-480b-b04a-7a6f3e428e8d
Environment
Zed: v0.120.6 (Zed) OS: macOS 13.5.2 Memory: 16 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.
No response
Thanks for writing this up. Undo and visual mode is a big wart in the vim emulation at the moment.
As you observe we just copy Zed's undo stack at the moment. I think we could likely improve this by returning to normal mode on undo, though we'd have to test it of course!
Getting better still will require us to remember which mode you were in (currently we can't distinguish between visual block, visual line, and visual on undo; so we need to store that on the selection that is written to the undo stack).
If you'd like to pair with me on some of this, please book time here: https://calendly.com/conradirwin/pairing!
Sacrificing the ability to use u for lowercase in visual mode (without any additions requiring you to do do U -> ~ to force upper then toggle) the following keybinds allows me to chain u for undos:
[
{
"context": "Editor && vim_mode == normal && vim_operator == none && !VimWaiting",
"bindings": {
"u": "editor::Undo"
}
},
{
"context": "Editor && vim_mode == visual && vim_operator == none && !VimWaiting",
"bindings": {
"u": "editor::Undo"
}
},
]
Just came across this issue. +1 for this.
I also run into this a lot