Question

I'm using the following mappings to manage the window size:

:nnoremap <kPlus> <C-W>+
:nnoremap <kMinus> <C-W>-
:nnoremap <kDivide> <C-W><
:nnoremap <kMultiply> <C-W>>

Adding the control prefix to map window jumping does not have any effect:

:nnoremap <C-kDivide> <C-W>h
:nnoremap <C-kMultiply> <C-W>l

Pressing <C-kMultiply> acts the same as <kMultiply>

Any idea why?

Was it helpful?

Solution

To expand on what ZyX said:

Keys like <C-kMultiply> will work fine in GVim, which receives keyboard input from the GUI environment, but they are impossible to represent in the stream that serves as terminal Vim's input, due to the venerable way that control characters are defined in it:

How control characters map to keyboards (Wikipedia)

The control modifier works by simply zeroing two high bits, so that for example G (​10​00111) becomes BEL (​00​00111). This means that it can only work with single-byte character codes: there's no way to apply it to multi-byte escape sequences such as what <kMultiply> actually sends.

(This is also why you can't generally combine Ctrl with Shift, in the terminal: both <C-G> and <C-g> end up as the same control character once the high bits are zeroed.)

What happens in the face of such an unrepresentable key combination varies from terminal to terminal: xterm, for example, will ignore the modifier and send <C-kMultiply> as <kMultiply>, while gnome-terminal will refuse to send the keypress altogether.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top