commit 5e846978e3bf85ea5ae5b505af267c01e98f6135
parent 48990a7077bb6767f3d218907344ee7fb0bfaaff
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sun, 26 Feb 2023 08:32:20 +0800
vim-patch:9.0.1354: "gr CTRL-G" stays in virtual replace mode
Problem: "gr CTRL-G" stays in virtual replace mode. (Pierre Ganty)
Solution: Prepend CTRL-V before control characters. (closes vim/vim#12045)
https://github.com/vim/vim/commit/d6a4ea3aa0d3f4a886ea900e94bf4e8ca8ae8d63
Cherry-pick Test_edit_gr_special() from patch 9.0.1347.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat:
3 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
@@ -3444,6 +3444,10 @@ static void ins_ctrl_g(void)
dont_sync_undo = kNone;
break;
+ case ESC:
+ // Esc after CTRL-G cancels it.
+ break;
+
// Unknown CTRL-G command, reserved for future expansion.
default:
vim_beep(BO_CTRLG);
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
@@ -4720,6 +4720,11 @@ static void nv_vreplace(cmdarg_T *cap)
if (cap->extra_char == Ctrl_V) { // get another character
cap->extra_char = get_literal(false);
}
+ if (cap->extra_char < ' ') {
+ // Prefix a control character with CTRL-V to avoid it being used as
+ // a command.
+ stuffcharReadbuff(Ctrl_V);
+ }
stuffcharReadbuff(cap->extra_char);
stuffcharReadbuff(ESC);
if (virtual_active()) {
diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim
@@ -2080,6 +2080,20 @@ func Test_edit_CTRL_hat()
bwipe!
endfunc
+" Test "gr" followed by an Insert mode command does get out of Insert mode.
+func Test_edit_gr_special()
+ enew
+ call setline(1, ['abcdef', 'xxxxxx'])
+ exe "normal! gr\<C-O>lx"
+ call assert_equal("\<C-O>def", getline(1))
+
+ call setline(1, 'abcdef')
+ exe "normal! 0gr\<C-G>lx"
+ call assert_equal("\<C-G>def", getline(1))
+
+ bwipe!
+endfunc
+
" Weird long file name was going over the end of NameBuff
func Test_edit_overlong_file_name()
CheckUnix