I\'m now switching to VIM
from TextMate. I found ^+W
in INSERT mode very useful. However, I\'d like to delete not only the word before cursor, but
The accepted answer fails when trying to repeat deleting words, try this solution instead:
" delete current word, insert and normal modes
inoremap <C-BS> <C-O>b<C-O>dw
noremap <C-BS> bdw
It maps CTRL-BackSpace, also working in normal mode.
I'd like to delete not only the word before cursor, but the word after or around cursor as well.
In that case the solution proposed by OP (i.e. using <c-w>
) can be combined with the accepted answer to give:
inoremap <c-d> <c-o>daw<c-w>
alternatively (shorter solution):
inoremap <c-d> <c-o>vawobd
Sample input:
word1 word2 word3 word4
^------------- Cursor location
Output:
word1 word4
Insert mode has no such command, unfortunately. In VIM, to delete the whole word under the cursor you may type viwd
in NORMAL mode. Which means "Visual-block Inner Word Delete". Use an upper case W
to include punctuation.
What you should do is create an imap of a certain key to a series of commands, in this case the commands will drop you into normal mode, delete the current word and then put you back in insert:
:imap <C-d> <C-[>diwi
Normal mode:
daw : delete the word under the cursor
caw : delete the word under the cursor and put you in insert mode
In old vi, b
moves the cursor to the beginning of the word before cursor, w
moves the cursor to the beginning of the word after cursor, e
moves cursor at the end of the word after cursor and dw
deletes from the cursor to the end of the word.
If you type wbdw
, you delete the word around cursor, even if the cursor is at the beginning or at the end of the word. Note that whitespaces after a word are considerer to be part of the word to be deleted.