Why does mapping the <C-…> key not work?

The only Ctrl-printable-key chords which Vim can reliably detect (because they are defined in the ASCII standard) are the following:

        [email protected]                 0x00            NUL

        Ctrl-A to Ctrl-Z       0x01 to 0x1A

        Ctrl-a to Ctrl-z       0x01 to 0x1A

        Ctrl-[                 0x1B            ESC

        Ctrl-\                 0x1C

        Ctrl-]                 0x1D

        Ctrl-^                 0x1E

        Ctrl-_                 0x1F

        Ctrl-?                 0x7F            DEL

Most of these, however, already have a function in Vim (and some are aliases of other keys: Ctrl-H and Bsp, Ctrl-I and Tab, Ctrl-M and Enter, Ctrl-[ and Esc, Ctrl-? and Del). The “safest” keys to use in Vim for the {lhs} of a mapping are the F keys, with or without Shift: <F2> to <F12> and <S-F1> to <S-F12>. (Some OSes, including mine, intercept Ctrl-Fn and Alt-Fn, which never reach an application program such as vim or gvim). You can try other combinations of Ctrl + any key, but they may either not work everywhere (e.g. the terminal might not pass that key to Vim, or they might have unintended side effects (e.g. mapping <C-I> means also to map <Tab>). If you are using a recent xterm as terminal, Vim is able to actually distinguish most Ctrl,Alt,Shift (and even distinguish Ctrl-I from Tab, etc) mappings by making use of the modifyOtherKeys feature of xterm. See the xterm documentation: https://invisible-island.net/xterm/modified-keys.html and https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys For terminals that pretend to be xterm, vim will try to enable this feature. You can check, if this feature is enabled in your Vim by typing CTRL-SHIFT-V CTRL-V in insert mode. If the result is a single byte, then the feature is off, when the feature is enabled, Vim will print: <1b>27;5;118~. Note: that your desktop environment or terminal might intercept the key press, to e.g. paste the clipboard If this feature causes problems, you can disable it: let &t_TI = ‘’ let &t_TE = ‘’ It does not take effect immediate, run a shell command after changing those values: :!true

Read free Software Algorithms and Computer Science Books by CodeAhoy Learn.

Introduction to Recursion and Backtracking

Sorting Algorithms

Introduction to C Programming Language

And More...

Speak Your Mind