]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1693: Ctrl-Q not handled like Ctrl-V in replace mode v9.0.1693
authorChristian Brabandt <cb@256bit.org>
Fri, 11 Aug 2023 22:03:57 +0000 (00:03 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 11 Aug 2023 22:03:57 +0000 (00:03 +0200)
Problem: Ctrl-Q not handled like Ctrl-V in replace mode
Solution: Handle Ctrl-Q like Ctrl-V

closes: #12686
closes: #12684

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/normal.c
src/testdir/test_normal.vim
src/version.c

index 4004d420453bbf9542608df590e9241185c497c4..1aad0b1b3aef5620ea7c489683cbe5e0fd90836f 100644 (file)
@@ -4767,7 +4767,7 @@ nv_replace(cmdarg_T *cap)
 #endif
 
     // get another character
-    if (cap->nchar == Ctrl_V)
+    if (cap->nchar == Ctrl_V || cap->nchar == Ctrl_Q)
     {
        had_ctrl_v = Ctrl_V;
        cap->nchar = get_literal(FALSE);
@@ -5051,7 +5051,8 @@ nv_vreplace(cmdarg_T *cap)
        emsg(_(e_cannot_make_changes_modifiable_is_off));
     else
     {
-       if (cap->extra_char == Ctrl_V)  // get another character
+       if (cap->extra_char == Ctrl_V || cap->extra_char == Ctrl_Q)
+           // 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
index a3d9454d2c01ec9cd48d56dccfae8f60b9255c40..1754fb8d17bbfec051b6694df4acaa4dd7a88e39 100644 (file)
@@ -3998,4 +3998,42 @@ func Test_normal_j_below_botline()
   call StopVimInTerminal(buf)
 endfunc
 
+" Test for r (replace) command with CTRL_V and CTRL_Q
+func Test_normal_r_ctrl_v_cmd()
+  new
+  call append(0, 'This is a simple test: abcd')
+  exe "norm! 1gg$r\<C-V>\<C-V>"
+  call assert_equal(['This is a simple test: abc\16', ''], getline(1,'$'))
+  exe "norm! 1gg$hr\<C-Q>\<C-Q>"
+  call assert_equal(['This is a simple test: ab\11\16', ''], getline(1,'$'))
+  exe "norm! 1gg$2hr\<C-V>x7e"
+  call assert_equal(['This is a simple test: a~\11\16', ''], getline(1,'$'))
+  exe "norm! 1gg$3hr\<C-Q>x7e"
+  call assert_equal(['This is a simple test: ~~\11\16', ''], getline(1,'$'))
+
+  if &encoding == 'utf-8'
+    exe "norm! 1gg$4hr\<C-V>u20ac"
+    call assert_equal(['This is a simple test:€~~\11\16', ''], getline(1,'$'))
+    exe "norm! 1gg$5hr\<C-Q>u20ac"
+    call assert_equal(['This is a simple test€€~~\11\16', ''], getline(1,'$'))
+    exe "norm! 1gg0R\<C-V>xff WAS  \<esc>"
+    call assert_equal(['ÿ WAS   a simple test€€~~\11\16', ''], getline(1,'$'))
+    exe "norm! 1gg0elR\<C-Q>xffNOT\<esc>"
+    call assert_equal(['ÿ WASÿNOT simple test€€~~\11\16', ''], getline(1,'$'))
+  endif
+
+  call setline(1, 'This is a simple test: abcd')
+  exe "norm! 1gg$gr\<C-V>\<C-V>"
+  call assert_equal(['This is a simple test: abc\16', ''], getline(1,'$'))
+  exe "norm! 1gg$hgr\<C-Q>\<C-Q>"
+  call assert_equal(['This is a simple test: ab\11 ', ''], getline(1,'$'))
+  exe "norm! 1gg$2hgr\<C-V>x7e"
+  call assert_equal(['This is a simple test: a~\11 ', ''], getline(1,'$'))
+  exe "norm! 1gg$3hgr\<C-Q>x7e"
+  call assert_equal(['This is a simple test: ~~\11 ', ''], getline(1,'$'))
+
+  " clean up
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 1c528a30a9cda72c182fdc3f6e3b232ea7cd68e3..15368d255c536e6665c7fc7910b6eb989eed2dec 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1693,
 /**/
     1692,
 /**/