Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

In insert mode, Vim will delete back a word if you press <C-w> (control + w). Is there a similar command that deletes back a Word?

(Eg, would delete all of instead of just the com part.)

If not, I'm thinking of mapping <C-BS> (control + backspace) to do this.

share|improve this question

No, there is no such built-in command, but the following should do the trick:

:inoremap <silent> <expr> <C-S-BS>
\   col('.') == 1 ?
\       '<C-w>' :
\       col('.') >= col('$') ?
\           '<C-o>:normal! Bd$<CR>' :
\           '<C-o>:normal! m"Bdg`"<CR>'

When at the beginning of the line it just executes the <C-w> command to join with the previous line. At the end of the line, it goes back on WORD and deletes the rest. Otherwise, it establishes a temporary mark m", goes back one WORD B, and deletes that part of the text.

Edit: Fixed for cursor at end of the line

share|improve this answer
This is nice, but a little buggy. If my cursor is directly after whatever and I use it, I end up with r leftover. If my cursor is after whatever (after the space), it deletes the whole word but leaves two spaces after the previous word. – Nathan Long Dec 4 '12 at 16:45
This seems to work for me: imap <C-BS> <C-o>vBd. You seem to have more Vim-fu than I do. Do you see any downsides? If not, want to roll that into your solution? – Nathan Long Dec 4 '12 at 16:52
Using visual mode; that's clever! Unfortunately, it only works with :set selection=exclusive, and it clobbers the visual selection, which a well-behaved mapping shouldn't do. – Ingo Karkat Dec 4 '12 at 17:27
Ah, I didn't test for end of line; I've edited in a fix. Now it's even more ugly than your alternative, though. – Ingo Karkat Dec 4 '12 at 17:28

If I understood, you are on a file in insert mode with your cursor on a char somewhere on 'com' and you press <c-w> to delete and stay in insert mode ?

blabla ffd fds fsdf dsfd

this key map do the trick : imap <C-w> <ESC>lciW

<ESC> -> go in normal

l -> goto right (because when press ESC it goes to left)

ciW -> replace all Word and go in insert mode

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.