Skip to content

vim: Fix dot repeat ignoring recorded register#50753

Merged
dinocosta merged 6 commits intozed-industries:mainfrom
feitreim:bugfix-vim-repeat-registers
Mar 16, 2026
Merged

vim: Fix dot repeat ignoring recorded register#50753
dinocosta merged 6 commits intozed-industries:mainfrom
feitreim:bugfix-vim-repeat-registers

Conversation

@feitreim
Copy link
Copy Markdown
Contributor

@feitreim feitreim commented Mar 4, 2026

Closes #49867

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.

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:

  • Fixed vim's repeat . to preserve the register the recorded command used
  • Updated vim's repeat . to increment the recorded register when using numbered registers

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.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 4, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 4, 2026
Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
    3
    

    If one is to use "1yy to 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 "ayy to yank the first line, then move to the second line with j and use "b., you'll immediately see that the same original content has been pasted, as I suspect that . is not actually using the previous yy command, 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 🙂

@feitreim
Copy link
Copy Markdown
Contributor Author

feitreim commented Mar 11, 2026

@dinocosta

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.

**
Actually I am currently working to add a message or some kind of notification that for example with the first case you gave, register two is empty.
Done w/ that now.

@feitreim feitreim requested a review from dinocosta March 12, 2026 18:58
@dinocosta
Copy link
Copy Markdown
Member

@feitreim Thank you for updating this, will try to take another look soon!

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.

I usually just use nvim --clean when testing changes that should behave like NeoVim, might help 🙂

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.
Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feitreim Everything's looking good! 🙌

I've pushed a smaller commit just refactoring some bits and bobs, but it's good to go 🙂

@feitreim
Copy link
Copy Markdown
Contributor Author

Thank you!

I'll keep nvim --clean in mind going forward as well.

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.
@dinocosta dinocosta enabled auto-merge (squash) March 16, 2026 10:00
@dinocosta dinocosta merged commit 923b512 into zed-industries:main Mar 16, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vim] Repeat does not respect register

2 participants