Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Ctrl-Backspace to delete a word in vim within gnome-terminal?

I'd like Ctrl-Backspace to delete the current word in vim insert mode. From within xterm I can pull this off via

:inoremap <C-H> <C-W>

but in gnome-terminal I cannot figure out a way to make it happen.

When in vim insert mode, if I type control-v and then press backspace, I get ^H in xterm, and ^? in gnome-terminal. Unfortunately,

:inoremap <C-?> <C-W>

doesn't do the trick in gnome-terminal; control-backspace just erases a single character no matter what.

Regarding ASCII codes:

Gnome-terminal lets you change the backspace character under Edit -> Profile Preferences -> Compatibility. Unfortunately, no option works, as far as I can tell: whatever character I apply to Backspace via the settings, if I try mapping the character itself, like

:inoremap <C-H> <C-W>

then regular backspace and control-backspace both erase an entire word; and if I try mapping control plus that character, like

:inoremap <C-^H> <C-W>

then regular backspace and control-backspace just erase a single character.

like image 409
Michael Gundlach Avatar asked Apr 26 '10 17:04

Michael Gundlach


People also ask

How do I Ctrl backspace in VIM?

If the mapping is always wanted, place the above in your vimrc.

How do I delete a word in Linux terminal?

Ctrl + K = Delete right of the cursor. Ctrl + W = Delete word on the left.

How do I delete a single word in terminal?

If you press the ESC key followed by backspace the last word will be deleted!

How do you go backspace in Terminal?

Pressing the backspace key on a computer terminal would generate the ASCII code 08, BS or Backspace, a control code which would delete the preceding character. That control code could also be accessed by pressing Control-H, as H is the eighth letter of the Latin alphabet.


1 Answers

gnome-terminal's libvte would need to be patched.

libvte already has several options to map backspace, none of which distinguish Ctrl-backspace. It needs an option that does, maybe one that follows the behaviour of the linux console (^? for backspace, ^H for Ctrl-backspace). See this gnome bug.


2015 update: this was fixed in 23c7cd0f99d504cbab06d4c27254d4f3e2807ba8.

libvte 0.41.90, 0.40.3 and newer have the fix.

like image 100
Tobu Avatar answered Nov 15 '22 17:11

Tobu