Reputation: 63
Does anyone know how to delete the word in front of the cursor while in insert mode in Vim? Most systems use Ctrl+Del
to do this.
I know to delete the word behind the cursor in Vim is Ctrl+w
while in insert mode, but I don't know how to delete forward.
Upvotes: 6
Views: 4742
Reputation: 31
Placing
imap <C-Del> <Esc>lce
in .vimrc
works with Ctrl+Delete
for me in the same way that Ctrl+Backspace
works with
imap <C-BS> <C-W>
in insert mode
Upvotes: 0
Reputation: 528
The accepted solution is not exactly correct, right? It does delete backwards but not forward
In nvim this works:
imap <C-Del> X<Esc>ce
Upvotes: 0
Reputation: 3826
Add this to your ~/.vimrc
(for VIM or GVIM):
imap <C-D> X<Esc>lbce
; 1 2 3 4 5 ; just a comment for the further description
(In GVIM, <C-Del>
also works.)
Ctrl+D
in the insert mode.If a word is removed, then the cursor will be at the same position as the first character of the word was.
Upvotes: 6
Reputation: 1244
Use a single normal mode command, whilst in insert mode.
To do this, whilst in insert mode, type
Ctrl+o
This tells vim to accept exactly 1 command as if it were normal mode. Then press
dw
to delete a word.
Upvotes: 6