I recently noticed that in normal mode when I type Ctrl-i (command for jumps) it is "confused" for the TAB key. In particular, I have this mapping:
nnoremap <Tab> :tabnext<Enter>
I recently noticed that in normal mode when I type Ctrl-i (command for jumps) it is "confused" for the TAB key. In particular, I have this mapping:
nnoremap <Tab> :tabnext<Enter>
Terminal I/O applications just see the composed characters sent by the terminal, and cannot distinguish amongst specific key chords, while GUI applications can, because GUIs tend to operate in terms of key press and release messages.
Most terminals, and most terminal emulators, send a ␉ (U+0009) character down the (virtual) wire to the host system when either ⇥ Tab or ⎈ Control+I are pressed. This is not vim
. This is how terminals work, and how the emulators that emulate them work too.
Similarly, and oft forgotten nowadays I observe, these terminals and terminal emulators send a ␛ (U+001B) character down the (virtual) wire to the host system when either ⎋ Esc or ⎈ Control+[ are pressed.
Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab>
/ <C-I>
, <CR>
/ <C-M>
/ <Esc>
/ <C-[>
etc. (Only exception is <BS>
/ <C-H>
.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.
Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. https://groups.google.com/forum/#!topic/vim_dev/Ym6D-kWIsyo
But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim release.
Ctrl+i
andTab
are identical. Just likeCtrl+[
andEsc
. If you compare what ASCII codes are sent forTab
andCtrl+i
(by typing intood
for example), you will see that both produces ASCII 9 (011 in octal), which corresponds to "horizontal tab". – Kusalananda Jan 22 '20 at 16:50vim
in the terminal, there's nothingvim
could do about it:Ctrl-I
,Tab
,Ctrl-Tab
, etc are the same. But you could change your terminal emulator to send a different sequence forCtrl-I
, eg.\E[Y
, and then remap that key invim
. Example withxterm
:xterm -xrm '*VT100*translations: #override\n\Ctrl<Key>i:string("\033[Y")'
– Jan 22 '20 at 17:18