0

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>
  • Ctrl+i and Tab are identical. Just like Ctrl+[ and Esc. If you compare what ASCII codes are sent for Tab and Ctrl+i (by typing into od for example), you will see that both produces ASCII 9 (011 in octal), which corresponds to "horizontal tab". – Kusalananda Jan 22 at 16:50
  • If you're running vim in the terminal, there's nothing vim 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 for Ctrl-I, eg. \E[Y, and then remap that key in vim. Example with xterm: xterm -xrm '*VT100*translations: #override\n\Ctrl<Key>i:string("\033[Y")' – mosvy Jan 22 at 17:18
3

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.

GUI applications can distinguish amongst specific key chords, because GUIs tend to operate in terms of key press and release messages. Terminal I/O applications just see the composed characters sent by the terminal, and cannot.

| improve this answer | |
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.