Skip to content

Conversation

@andrewgazelka
Copy link
Contributor

Summary

  • In vim, pressing Escape to exit insert mode moves the cursor left by one position
  • This is because insert mode positions the cursor between characters, while normal mode positions it on a character
  • Without this fix, repeatedly pressing i <esc> i <esc> would not move the cursor backward as expected

Test plan

  • Added test esc_from_insert_mode_moves_cursor_left
  • Updated existing test to explicitly test Esc from normal mode
  • All 756 tests pass

In vim, pressing Escape to exit insert mode moves the cursor left by one
position. This is because insert mode positions the cursor between
characters, while normal mode positions it on a character.

Without this fix, repeatedly pressing "i <esc> i <esc>" would not move
the cursor backward as expected in vim.
@andrewgazelka andrewgazelka marked this pull request as ready for review December 16, 2025 03:49
@blindFS
Copy link
Contributor

blindFS commented Dec 16, 2025

Thanks for trying to improve vi keybindings.

I see the point of aligning the behaviors of reedline vi-mode with those of vim/neovim.

But I don't think this specific one is very useful. It somehow reveals that we may have a bigger issue of wrong calculations of cursor positions within vi mode, see also #927. It would be better to fix them all-together with some fundamental changes/redesigning than this kind of case-wise tuning.

@andrewgazelka
Copy link
Contributor Author

Hmmm makes sense.

@andrewgazelka
Copy link
Contributor Author

Thanks for trying to improve vi keybindings.

I see the point of aligning the behaviors of reedline vi-mode with those of vim/neovim.

But I don't think this specific one is very useful. It somehow reveals that we may have a bigger issue of wrong calculations of cursor positions within vi mode, see also #927. It would be better to fix them all-together with some fundamental changes/redesigning than this kind of case-wise tuning.

you want literally 1:1? what must be added

@blindFS
Copy link
Contributor

blindFS commented Dec 17, 2025

Thanks for trying to improve vi keybindings.

I see the point of aligning the behaviors of reedline vi-mode with those of vim/neovim.

But I don't think this specific one is very useful. It somehow reveals that we may have a bigger issue of wrong calculations of cursor positions within vi mode, see also #927. It would be better to fix them all-together with some fundamental changes/redesigning than this kind of case-wise tuning.

you want literally 1:1?

Not necessarily, just taking those off-by-1 issues like #766 into account. And you may find a better way to fix them.

what must be added

Actually I don't have a clear view of how to do it.

@blindFS
Copy link
Contributor

blindFS commented Jan 16, 2026

@fdncred @ysthakur any thought?

@ysthakur
Copy link
Member

ysthakur commented Jan 16, 2026

I agree with @blindFS that we should try to fix the source of the off-by-ones rather than fix individual issues downstream.

By the way, we already had a PR for this with a very similar implementation: #699. It got reverted in #773 because it broke history search somehow: #772. I'm not sure if your implementation suffers from the same bug, but make sure to test that.

@fdncred
Copy link
Contributor

fdncred commented Jan 16, 2026

I thought this looked familiar. Thanks yash! I agree with yash and bfs.

@andrewgazelka
Copy link
Contributor Author

btw I currently do not have capacity to make improvements to this so feel free to take over if this impl is best fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants