Skip to main content

Annoying Linux: Ctrl-Backspace

·2 mins

In the majority of systems that I interact with, Ctrl - /, means “move one word left or right”. And naturally then, Ctrl - /Delete, means “delete previous word or “delete next word”.

On the graphical side of Linux systems, this seems to be the default behavior, but not when interacting with the terminal.

In bash and zsh, Ctrl - Delete behaves as expected, but adding Ctrl to doesn’t change it’s behavior at all. Instead, you’ll notice that Alt - does what you expect. This probably stems from the ancient history of emacs.

And in vim, nothing works (surprised?).

How do we fix it? #

For bash, we can fix this by adding: "\C-H":"\C-W" to ~/.inputrc.

What does that string even mean? And how does it work?

That’s a tangent I don’t want to get into right now. Checkout the Further reading section if you’re interested.

For zsh, we have to use bindkey. Add this line to your ~/.zshrc file:

bindkey '^H' backward-kill-word

And finally, vim. To fix Ctrl - Delete, you can simply add this to ~/.vimrc

" Make Ctrl-Delete delete the next word in "normal mode"
nnoremap <C-Del> dw
" ditto "insert mode"
inoremap <C-Del> <C-o>dw

But to fix Ctrl - , I can’t just ask you to copy paste some text, because the ^H in the snippet below is just a visual representation of the actual value.

Open ~/.vimrc with vim. Then, instead of writing ^H in the file, in insert mode, press Ctrl - V and then Ctrl - . You should then see a ^H appear.

In the end, you should have this:

" Equivalent for ctrl-backspace
nnoremap ^H db
inoremap ^H <C-o>db

See you in the next one!

Further reading #