How to Get Ctrl-Backspace to Delete a Word in Vim Within Gnome-Terminal

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

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.

In zsh how do you bind Ctrl+backspace to delete the previous word?

One may use bindkey '^H' backward-kill-word.

Note that, on old versions of GNOME terminal, it won't work; see How do I get Ctrl-Backspace to delete a word in vim within gnome-terminal? and Bug 420039 - VTE doesn't distinguish between backspace and control-backspace.

As reported by thorbjornwolf in his comment, commit 23c7cd0f fixed it.

Vim backspace key only works on new text

Wow, second time I've figured out the answer minutes after posting the question.

set backspace=indent,eol,start

Must have been set automatically by the distro's package vimrc. Hope this answer helps someone else! For more info:

:help i_backspacing

How to delete a whole word on the right in Linux Bash Shell command line

Use Esc + D or Alt + D to delete the word on the right.

VIM: set term=xterm changes BS to Del, is it reversible?

Vim's inoremap and nnoremap commands can be used to adjust how keys are interpreted in Vim.

A solution is documented here for your specific context: https://conemu.github.io/en/VimXterm.html

The relevant quote:
"If you have problems with BS in Vim (BS acts like Delete key) under ConEmu when term=xterm, you may try to remap BS key:

inoremap <Char-0x07F> <BS> 
nnoremap <Char-0x07F> <BS>

"

In general, when a key does not do what you want, the trick is to find out what it actually sends to Vim. Sometimes hitting Ctrl-V followed by that key in insert mode might help figure it out. Then inoremap and nnoremap as shown above can be used to reassign it to the behaviour you want in insert and normal modes, respectively.

vim backspace leaves ^?

^? is the delete character; the backspace character is ^H. Only one of these is recognized by your terminal as "erase", and this is determined by the terminal settings, stty. (bash and other shells understand this as a problem and do special things to recognize both)

If your terminal emulator (ssh, putty, xterm, whatever) disagrees with your terminal settings, then you see this behavior. Usually it's right by default, but very often people will put stty commands in their .bashrc which breaks things.

You probably have something like stty erase ^H in your bashrc. If you do, get rid of it, or change your terminal settings to have backspace send ^H instead of DEL (^?)

You can also fix this with vim mappings, but that's ignoring the basic problem.

Howto make Alt + NationalChar work as Alt + US-ASCII?

First, enter CTRL+V ALT+CyrChar in your shell. You should see something like "^[foo". The "foo" part is what bash sees when you press ALT+CyrChar. Then use bind '"\efoo":kill-word' to bind that to the kill-word command. Make sure you replace foo with exactly what follows the ^[.

For example to bind ALT+DELETE to kill-word, I would use bind '"\e[3;3~":kill-word' since CTRL+V ALT+ prints ^[[3;3~.



Related Topics



Leave a reply



Submit