Question

I still cannot for the life of me understand remapping keys in Vim. I have the following in my vimrc

" This works
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" But this doesn't?
nnoremap <C-+> <C-w>> " Should map to Ctrl +
nnoremap <C--> <C-w>< " Should map to Ctrl -

I'm trying to remap the window resize keybindings because they are a bit clumsy. Too many keypresses for too little movement. But why is it that the bottom two won't work if they are written in exactly the same way as the top two?

Was it helpful?

Solution

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. 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.

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 8 major release.

OTHER TIPS

I think the point is the historical meaning of the CTRL modifier in ASCII. On my system (Mac OS X, Vim 7.3) I get a = when I type <C-+> in Insert mode in the GUI, and I get a beep when I try it in a terminal.

Short version: not every key can be modified by <C->.

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