]> granicus.if.org Git - vim/commitdiff
patch 8.2.1811: mapping Ctrl-key does not work for '{', '}' and '|' v8.2.1811
authorBram Moolenaar <Bram@vim.org>
Wed, 7 Oct 2020 15:29:48 +0000 (17:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 7 Oct 2020 15:29:48 +0000 (17:29 +0200)
Problem:    Mapping Ctrl-key does not work for '{', '}' and '|'.
Solution:   Remove the shift modifier. (closes #6457)

runtime/doc/map.txt
src/misc2.c
src/testdir/test_termcodes.vim
src/version.c

index df96bde9410e6ea7de870241f8e8322b38607e47..cfd48b5a78cb6a0842f517afd1a7a6028fddbc0c 100644 (file)
@@ -839,8 +839,15 @@ execute a shell command, e.g.: `!ls`  Or put the lines in your |vimrc|.
 
 When modifyOtherKeys is enabled you can map <C-[> and <C-S-{>: >
        imap <C-[> [[[
-       imap <C-S-{> {{{
-Without modifyOtherKeys <C-[> and <C-S-{> are indistinguishable from Esc.
+       imap <C-{> {{{
+Without modifyOtherKeys <C-[> and <C-{> are indistinguishable from Esc.
+Note that <C-{> is used and not <C-S-[> or <C-S-{>.  This works on most
+keyboards.  Similarly, <C-}> is used instead of <C-S-]> or <C-S-}> and
+<C-|> instead of <C-S-\> or <C-S-|>.  Note that '|' has a special meaning in a
+mapping, see |map-bar|.
+
+WARNING: if you map <C-[> you may very well break any key codes that start
+with Esc.  Make sure it comes AFTER other mappings.
 
 A known side effect is that in Insert mode the raw escape sequence is inserted
 after the CTRL-V key.  This can be used to check whether modifyOtherKeys is
index b69714a8da09b43a5b6a82a9a9854dc095f59210..6316b53df4092a78102ffaac771109741db94547 100644 (file)
@@ -2974,7 +2974,8 @@ may_adjust_key_for_ctrl(int modifiers, int key)
 
 /*
  * Some keys already have Shift included, pass them as normal keys.
- * Not when Ctrl is also used, because <C-H> and <C-S-H> are different.
+ * When Ctrl is also used <C-H> and <C-S-H> are different, but <C-S-{> should
+ * be <C-{>.  Same for <C-S-}> and <C-S-|>.
  * Also for <A-S-a> and <M-S-a>.
  * This includes all printable ASCII characters except numbers and a-z.
  */
@@ -2989,6 +2990,11 @@ may_remove_shift_modifier(int modifiers, int key)
                || (key >= '[' && key <= '`')
                || (key >= '{' && key <= '~')))
        return modifiers & ~MOD_MASK_SHIFT;
+
+    if (modifiers == (MOD_MASK_SHIFT | MOD_MASK_CTRL)
+               && (key == '{' || key == '}' || key == '|'))
+       return modifiers & ~MOD_MASK_SHIFT;
+
     return modifiers;
 }
 
index 7d7e2f098738b09d8e0a16d3f0b5c865b9e91f27..424e285ef16de7b2bd8cefefb72d2fad9ca60409 100644 (file)
@@ -2126,6 +2126,24 @@ endfunc
 func Test_mapping_works_with_shift_ctrl()
   call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S', 6)
   call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S', 6)
+
+  new
+  set timeoutlen=10
+
+  " Ctrl-Shift-[ actually produces CTRL-Shift-{ which is mapped as <C-{>
+  call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6)
+  call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6)
+
+  " Ctrl-Shift-] actually produces CTRL-Shift-} which is mapped as <C-}>
+  call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6)
+  call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6)
+
+  " Ctrl-Shift-\ actually produces CTRL-Shift-| which is mapped as <C-|>
+  call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSI27'), 6)
+  call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSIu'), 6)
+
+  bwipe!
+  set timeoutlen&
 endfunc
 
 " Below we also test the "u" code with Alt, This works, but libvterm would not
index 140b3c8e209c6e9f726fc7666765fbdc86a0ff35..a2929bc3f79daa0e8933763edce77e6d65f709fa 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1811,
 /**/
     1810,
 /**/