Skip to content

Conversation

@chrisbra
Copy link
Member

Problem: Change operation may reset restart_edit when coming from a
mapping (Pierre Ganty).
Solution: Only save and restore restart_edit when insertmode is set;
handle commands coming from mappings the same as when they
were actually typed.

fixes: #18567

Problem:  Change operation may reset restart_edit when coming from a
          mapping (Pierre Ganty).
Solution: Only save and restore restart_edit when insertmode is set;
          handle commands coming from mappings the same as when they
          were actually typed.

fixes: vim#18567

Signed-off-by: Christian Brabandt <cb@256bit.org>
call setline(1, ['one two three', 'four five six'])
onoremap <buffer> gb <cmd>normal! V<cr>
call cursor(1, 2)
" the first <ESC> should enter insert mode directly
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
" the first <ESC> should enter insert mode directly
" the first <ESC> should exit insert mode directly

@zeertzjq
Copy link
Member

zeertzjq commented Oct 17, 2025

I'm not sure what the initial intention for this saving and restoring of restart_edit is, but (inferring from the description of patch 6.0.056) I can think of a case that this PR will break. Consider the following Normal mode mapping that changes the current line to abc:

nnoremap <F2> Vcabc<Esc>

Before this PR, when typing <F2> from i_CTRL-O, Vim returns to Insert mode like any other Normal mode operation, but after this PR Vim returns to Normal mode.

It's difficult to make everything work as expected...

@chrisbra
Copy link
Member Author

nnoremap <F2> Vcabc<Esc>

Before this PR, when typing from i_CTRL-O, Vim returns to Insert mode like any other Normal mode operation, but after this PR Vim returns to Normal mode.

correct, but it also means, there is an inconsistency between a command coming from a mapping and a command being interactively typed. If you type the right-hand side of the mapping interactively after C-O in insert mode, you end up in normal mode already, only when executing the mapping you remain in insert mode. I would think this is inconsistent and the mapping should behave like when being typed, no?

@zeertzjq
Copy link
Member

As I said, it's hard to decide what behavior one expects.

@chrisbra
Copy link
Member Author

yeah, it's gonna be a backwards incompatible change. Let's not do it (at least now).

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.

ESC not leaving insert mode after insert-mode + CTRL-o + operator mapping

2 participants