Gnome-terminal + Vim and Ctrl-Shift mappings

Solution 1:

I think the problem here is that you are trying to get vim, which expects to run in a terminal, to recognize a CTRL-SHIFT sequence. While it's possible for X to recognize such combinations, applications that run in a terminal (or, these days, a terminal emulator) cannot. This is because, historically, terminals could only send and receive seven- or eight-bit sequences of ASCII data across a serial connection (though this could include "escape sequences" that position the cursor, scroll or delete lines, change color and other helpful effects).

There are 32 "Control Codes" in the ASCII character set, including the familiar CTRL-A through CTRL-Z. But there are no corresponding ASCII codes for "CTRL-SHIFT" A through Z. Now, gnome-terminal itself can recognize these codes (CTRL-SHIFT-V, for instance, will paste text from the clipboard), but vim will not be able to have direct access to it.

Of course, it may be possible (I don't know) for a terminal emulator to be set up to convert CTRL-SHIFT key presses to an escape sequence which can then be recognized by a vim mapping.

=======

UPDATE

You might be interested in gvim, which is a graphical version of vim that runs as an X program rather than a terminal program. Maybe gvim will be able to understand CTRL-SHIFT codes?

Solution 2:

As Bartleby pointed out this is a terminal restriction, because vi sees the keycodes as being the same.

For terminals such as xterm you can change that. For gnome-terminal which ignores the X resources settings I don't know how to do the following:

This SO question covers the same topic, and this example shows this in use for mapping multiple keys in the .Xresources file. E.g.:

XTerm*vt100.translations: #override \
  Ctrl ~Meta Shift <Key>a: string(0x1b) string("[65;5u") \n\
  Ctrl ~Meta Shift <Key>b: string(0x1b) string("[66;5u") \n\ 
  Ctrl ~Meta Shift <Key>f: string(0x1b) string("[70;5u")  

Now we have different key sequences coming into vi for Ctrla vs. CtrlShifta, Ctrlb vs. CtrlShiftb, Ctrlf vs. CtrlShiftf.

We can now map them differently in ~/.vimrc:

map <ESC>[66;5u   :echo "ctrl-shift-b received"<CR>
map <ESC>[70;5u   :echo "ctrl-shift-f received"<CR>
map <C-b>         :echo "ctrl-b received"<CR>
map <C-f>         :echo "ctrl-f received"<CR>

Solution 3:

Seems to be an issue with GNOME Terminal not allowing certain combinations with the Ctrlkey. Searching online shows a lot of cases of this.

Just in case you don't know, Ctrl+page up/page down cycles through tabs.

Solution 4:

It seems you just have to disable all keyboard shortcuts in gnome-terminal.