Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've recently started using Vim. From previous editors, I'm used to deleting a whole word by pressing Ctrl-Backspace. After looking at the documentation I found that this was done by pressing Ctrl-w in Vim. The problem is that after getting used to pressing Ctrl-w, I've started closing tabs and chats every time I misspell a word (while writing this question I closed this tab 5 times). So I checked how to map keys in Vim and tried this:

:imap <C-BS> <C-w>

Unfortunately, it didn't work. After a bit of research I found that the terminal does not distinguish between Ctrl-Backspace and Backspace. I saw some hacks and patches to fix this issue, but I couldn't get them to work on terminator (which is the emulator I want to use).

Is there any way to map Ctrl-Backspace in Vim when using terminator?

share|improve this question
Welcome in Vim hell. – romainl Feb 25 '13 at 13:07
I like the fact that this hell is quite productive and can be improved with patches. – Ingo Karkat Feb 25 '13 at 13:10
BTW, I'm collecting these kind of questions to hopefully be able to make a case that this particular problem is tackled in a Vim 8.0. I really want more and more uniform mapping candidates, too. – Ingo Karkat Feb 25 '13 at 13:13
This problem can't really be fixed in vim (AFAIK). It depends on the terminal vim is running in. For a wide variety of users using vte (Gnone Terminal, Mate Terminal, Guake, etc) this problem has gotten some recent attention and might be fixed soon. See this gnome bug: – trusktr Oct 13 '13 at 15:21
@IngoKarkat See the above comment. ^ – trusktr Oct 13 '13 at 15:24
up vote 7 down vote accepted

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, cp.

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.

share|improve this answer
Thanks for the quick answer. I guess I'll just have to get used to using ctrl-w for vim and ctrl-backspace for browsers. – user1026044 Feb 25 '13 at 13:35
The good thing about Ctrl-W is that it also works in Bash etc. – Ingo Karkat Feb 25 '13 at 14:09
Yeah, I know. But you still have to use ctrl-backspace for everything else, and the fact that ctrl-w seems to be standard for closing tabs and windows everywhere else makes it annoying. I'll probably get used to it after a while though. – user1026044 Feb 25 '13 at 14:26
But can this be solved purely in the vim code base? How any code in the vim code base distinguish between backspace and ctrl+backspace if the terminal it is running in sends vim the same exact input for either key combination? Seems like this is something that must be fixed in the terminal that vim is running in, not vim. For example, Guake sends ^? for both backspace and ctrl+backspace, which makes them (AFAIK) indistinguishable. xterm, on the other hand, sends ^H for backspace and ^? for ctrl+backspace, making them distinguishable. – trusktr Oct 13 '13 at 15:25
But unfortunately, in xterm, backspace (^H) is indistinguishable from ctrl+h (^H). Perhaps we can create a new escape sequence to be able to distinguish all three? I don't know how easy that is, but it seems like it'd be safe to do because with the current state of things (some terminals use ^? for backspace, others ^H, and vice versa) I can't imagine very many terminal apps (if any at all) consider the ctrl+backspace scenario (it'd be completely indeterministic due to the variety of terminals)... – trusktr Oct 13 '13 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .