vim: Fix dot repeat ignoring recorded register#50753
vim: Fix dot repeat ignoring recorded register#50753dinocosta merged 6 commits intozed-industries:mainfrom
Conversation
When a command used an explicit register (e.g. `"_dd` or `"add`), the subsequent dot repeat (`.`) was ignoring that register and using the default instead. Store the register at recording start in `recording_register_for_dot`, persist it to `recorded_register` when recording stops, and restore it in `Vim::repeat` when no explicit register is supplied for `.`. An explicit register on `.` (e.g. `"b.`) still takes precedence.
dinocosta
left a comment
There was a problem hiding this comment.
Hey @feitreim 👋
Thank you for taking a look at this one! Seems to be headed in the right direction!
While testing this and comparing to Neovim's behavior, I noticed that it appears that Neovim doesn't behave exactly like we have in tests. Here's two scenarios where I was able to spot a difference:
-
Neovim actually increments the register number when it is used in a repeat action. For example, with the following text:
1 2 3If one is to use
"1yyto yank the first line to register 1, then use"1p, one is able to see that the first line is pasted, however, pressing.will now show the error "Nothing in register 2", another.press shows "Nothing in register 3", etc. -
It seems the named registers also don't behave exactly like what is available in tests? Take the same example shown above but, this time around, we use
"ayyto yank the first line, then move to the second line withjand use"b., you'll immediately see that the same original content has been pasted, as I suspect that.is not actually using the previousyycommand, so we might need to think a little bit better on how registers interact with dot repeat
Lastly, it'd be better if we could use NeovimBackedTestContext here and ensure our tested behavior matches Neovim's 🙂
|
hi! I updated all of the behaviors, and switched the tests to be backed by neovim and buffed them up a bit, got everything passing and manually verified the behaviors. I think that my neovim config is a bit weirder than I thought which I will keep in mind in the future, and use the nvim backed tests. ** |
|
@feitreim Thank you for updating this, will try to take another look soon!
I usually just use |
There were now 4 different places where we were setting the `Vim::status_label` field and then calling `cx.notify`, so a helper method, `Vim::set_status_label` was introduced, that simply receives the label. Since the notify call can be done on `Context<Editor>` was it was already being done in `Vim::show_location`, we can drop the tracking of the empty register and simply call the new method where we were updating the `register_empty` variable to `true`. Lastly, a new test that specifically checks how the repeat action deals with registers has been introduced, and the existing test has been refactored to use `assert_eq` instead of `assert_matches` so we get a more visual representation of the expected output, making it easier to update according to what we expect the result to be.
dinocosta
left a comment
There was a problem hiding this comment.
@feitreim Everything's looking good! 🙌
I've pushed a smaller commit just refactoring some bits and bobs, but it's good to go 🙂
|
Thank you! I'll keep |
Rename `vim::state::VimGlobals::recorded_register` to `vim::state::VimGlobals::recorded_register_for_dot` to make it more explicit that this field is meant to be used for dot-repeating logic.
Closes #49867
When a command used an explicit register (e.g.
"_ddor"add), the subsequent dot repeat (.) was ignoring that register and using the default instead.Store the register at recording start in
recording_register_for_dot, persist it torecorded_registerwhen recording stops, and restore it inVim::repeatwhen no explicit register is supplied for.. An explicit register on.(e.g."b.) still takes precedence.I am not 100% confident this is the best or cleanest way to introduce this behavior, of course open to suggestions.
I added and verified the behavior of tests + video of the behavior described in the bug report.
Screen.Recording.2026-03-04.at.4.41.13.PM.mov
Release Notes:
.to preserve the register the recorded command used.to increment the recorded register when using numbered registers