Ozkan
Ozkan

Reputation: 4160

map `ctrl +` to tabn

I am trying to map CTRL-+ to :tabn. But it does not work.

inoremap <C-+> :tabn<CR>
inoremap <C--> :tabp<CR>
nnoremap <C-+> :tabn<CR>
nnoremap <C--> :tabp<CR>

It does not work in insert mode also not in normal mode.

If I try the following (without CTRL), then it works, but then I can't switch tabs when I am in insert mode:

nnoremap + :tabn<CR>
nnoremap - :tabp<CR>

How can I map CTRL-+ to :tabn so I can switch tabs when in insert mode?

Upvotes: 1

Views: 407

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172530

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.

For me (in English Windows GVIM), it is possible to map Ctrl + - as <C-_>, though.

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.

Upvotes: 2

Prince Goulash
Prince Goulash

Reputation: 15715

Only a few control-printable key chords can be detected (and therefore mapped) by Vim, and these are listed in the FAQ. Unfortunately <CTRL-+> and <CTRL--> are not mentioned in this list, so it looks like such mappings are impossible.

There is on-going discussion about whether to redesign Vim's key model, but this probably have to wait until Vim 8.0. I am not optimistic.

Upvotes: 1

Related Questions