Vim Tips Wiki

Map Ctrl-Backspace to delete previous word

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 189 Printable Monobook Previous Next

created January 2, 2002 · complexity basic · author Robert Ames · version 6.0

In insert mode, pressing Ctrl-W deletes the previous word (:help word). If a non-Vim method is wanted, the following mapping can be used in gvim to allow Ctrl-Backspace to be used instead of Ctrl-W:

" Map Ctrl-Backspace to delete the previous word in insert mode.
:imap <C-BS> <C-W>

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

By default, Ctrl-W only deletes previous words in the text entered after last starting insert mode, and stops deleting text at the beginning of a line. The 'backspace' option can be set to control what is wanted. For example, the following causes Ctrl-W to always delete the previous word:

:set backspace=indent,eol,start


See alsoEdit


Mapping Ctrl-Backspace does not work in terminal Vim. Following is a workaround.

noremap! <C-BS> <C-w>
noremap! <C-h> <C-w>

There are some issues with <C-w>. For example it considers the insert mode's point of entry as a word boundary. Also, in readline <C-w> usually means to kill the previous WORD. There is a way to make it more readline-ish:

inoremap <C-w> <C-\><C-o>dB
inoremap <C-BS> <C-\><C-o>db

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki