Skip to content

Commit 4be18e7

Browse files
committed
patch 9.0.1276: some mappings with Meta and Shift do not work
Problem: Some mappings with Meta and Shift do not work. Solution: Apply the Shift modifier to the key. (issue #11913)
1 parent 78012f5 commit 4be18e7

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

runtime/doc/map.txt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ manual.
2020
1.8 Examples |map-examples|
2121
1.9 Using mappings |map-typing|
2222
1.10 Mapping alt-keys |:map-alt-keys|
23-
1.11 Mapping in modifyOtherKeys mode |modifyOtherKeys|
24-
1.12 Mapping with Kitty keyboard protocol |kitty-keyboard-protocol|
25-
1.13 Mapping an operator |:map-operator|
23+
1.11 Mapping meta-keys |:map-meta-keys|
24+
1.12 Mapping in modifyOtherKeys mode |modifyOtherKeys|
25+
1.13 Mapping with Kitty keyboard protocol |kitty-keyboard-protocol|
26+
1.14 Mapping an operator |:map-operator|
2627
2. Abbreviations |abbreviations|
2728
3. Local mappings and functions |script-local|
2829
4. User-defined commands |user-commands|
@@ -794,8 +795,8 @@ otherwise you would not be able to use those commands anymore. Here are a few
794795
suggestions:
795796
- Function keys <F2>, <F3>, etc.. Also the shifted function keys <S-F1>,
796797
<S-F2>, etc. Note that <F1> is already used for the help command.
797-
- Meta-keys (with the ALT key pressed). Depending on your keyboard accented
798-
characters may be used as well. |:map-alt-keys|
798+
- Any key with the Alt or Meta key pressed. Depending on your keyboard
799+
accented characters may be used as well. |:map-alt-keys|
799800
- Use the '_' or ',' character and then any other character. The "_" and ","
800801
commands do exist in Vim (see |_| and |,|), but you probably never use them.
801802
- Use a key that is a synonym for another command. For example: CTRL-P and
@@ -928,6 +929,8 @@ out whether ALT was pressed or not.
928929

929930
If the terminal supports the modifyOtherKeys mode and it has been enabled,
930931
then Vim can recognize more key combinations, see |modifyOtherKeys| below.
932+
The Kitty keyboard protocol works in a similar way, see
933+
|kitty-keyboard-protocol|.
931934

932935
By default Vim assumes that pressing the ALT key sets the 8th bit of a typed
933936
character. Most decent terminals can work that way, such as xterm, aterm and
@@ -966,7 +969,21 @@ on the terminal; that's a good last resource in case you want to send ESC when
966969
using other applications but not when inside Vim.
967970

968971

969-
1.11 MAPPING IN modifyOtherKeys mode *modifyOtherKeys*
972+
1.11 MAPPING META-KEYS *:map-meta-keys*
973+
974+
Mapping keys with the Meta modifier works very similar to using the Alt key.
975+
What key on your keyboard produces the Meta modifier depends on your keyboard
976+
and configuration.
977+
978+
Note that mapping <M-a> actually is for using the Alt key. That can be
979+
confusing! It cannot be changed, it would not be backwards compatible.
980+
981+
For the Meta modifier the "T" character is used. For example, to map Meta-b
982+
in Insert mode: >
983+
:imap <T-b> terrible
984+
985+
986+
1.12 MAPPING IN modifyOtherKeys mode *modifyOtherKeys*
970987

971988
Xterm and a few other terminals can be put in a mode where keys with modifiers
972989
are sent with a special escape code. Vim recognizes these codes and can then
@@ -1028,7 +1045,7 @@ When the 'esckeys' option is off, then modifyOtherKeys will be disabled in
10281045
Insert mode to avoid every key with a modifier causing Insert mode to end.
10291046

10301047

1031-
1.12 MAPPING WITH KITTY KEYBOARD PROTOCOL *kitty-keyboard-protocol*
1048+
1.13 MAPPING WITH KITTY KEYBOARD PROTOCOL *kitty-keyboard-protocol*
10321049

10331050
If the value of 'term' contains "kitty" then Vim will send out an escape
10341051
sequence to enable the Kitty keyboard protocol. This can be changed with the
@@ -1055,7 +1072,7 @@ translated). The meaning of {value}:
10551072
previous state is unknown
10561073

10571074

1058-
1.13 MAPPING AN OPERATOR *:map-operator*
1075+
1.14 MAPPING AN OPERATOR *:map-operator*
10591076

10601077
An operator is used before a {motion} command. To define your own operator
10611078
you must create a mapping that first sets the 'operatorfunc' option and then

src/term.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5343,6 +5343,12 @@ handle_key_with_modifier(
53435343

53445344
int key = trail == 'u' ? arg[0] : arg[2];
53455345
int modifiers = decode_modifiers(arg[1]);
5346+
5347+
// Some terminals do not apply the Shift modifier to the key. To make
5348+
// mappings consistent we do it here. TODO: support more keys.
5349+
if ((modifiers & MOD_MASK_SHIFT) && key >= 'a' && key <= 'z')
5350+
key += 'A' - 'a';
5351+
53465352
return put_key_modifiers_in_typebuf(key, modifiers,
53475353
csi_len, offset, buf, bufsize, buflen);
53485354
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1276,
698700
/**/
699701
1275,
700702
/**/

0 commit comments

Comments
 (0)