Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.vimrc mapping for control key not working

Tags:

vim

I have the below mapping in my .vimrc for mapping control key + 1, 2, 3.. for switching tabs. I am using gnome terminal in ubuntu 11.10, the control key mappings does not seem to work. could any one tell what I am doing wrong.

VIM - Vi IMproved version 7.3.154

map <C-S-]> gt
map <C-S-[> gT
map <C-1> 1gt
map <C-2> 2gt
map <C-3> 3gt
map <C-4> 4gt
map <C-5> 5gt
map <C-6> 6gt
map <C-7> 7gt
map <C-8> 8gt
map <C-9> 9gt
map <C-0> :tablast<CR>
syntax on
set shiftwidth=2
like image 504
vumaasha Avatar asked Apr 06 '13 10:04

vumaasha


People also ask

How do you Ctrl in Vim?

A key with the Ctrl key modifier is represented using the <C-key> notation. For example Ctrl-R is represented using <C-R>. A key with the Shift key modifier is represented using the <S-key> notation.

How do I map a key in Vimrc?

Creating keymaps To map a sequence of keys to execute another sequence of keys, use the ':map' command. For example, the following command maps the <F2> key to display the current date and time. The ':map' command creates a key map that works in normal, visual, select and operator pending modes.

How do you check if a key is mapped in Vim?

Use :map! and :map for manually set keys and :help 'char(-combination)' to find out which keys are already mapped in vim out-of-the-box(/out of your specific compiling options).

What is silent in Vim mapping?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.


1 Answers

First ensure that your terminal emulator (Gnome Terminal) doesn't swallow the key combinations for its own functionality; by default Ctrl + number switches tabs. But I'm afraid you still won't be able to use all those combinations...

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.

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.

like image 139
Ingo Karkat Avatar answered Nov 12 '22 21:11

Ingo Karkat