How do I delete the word before the cursor without leaving insert mode?
Answer
<C-w>
Explanation
Pressing <C-w> in insert mode deletes the word before the cursor instantly, without requiring you to switch to normal mode. This is one of several insert-mode editing shortcuts that dramatically reduce mode-switching overhead during fast typing and correction.
How it works
<C-w>deletes backward from the cursor to the beginning of the previous word- It removes the word and any whitespace between the cursor and the word boundary
- The deletion happens in place — you stay in insert mode, ready to continue typing
- It follows the same word boundary rules as
bin normal mode
Example
You are typing in insert mode and realize you used the wrong variable name:
const result = calculateWrong|
(| represents the cursor.) Press <C-w> and the last word is deleted:
const result = |
Now type the correct name:
const result = calculateCorrect|
You never left insert mode.
Other insert-mode editing shortcuts
<C-w> Delete the word before the cursor
<C-u> Delete from the cursor to the start of the line
<C-h> Delete one character before the cursor (same as Backspace)
<C-t> Indent the current line by one shiftwidth
<C-d> Unindent the current line by one shiftwidth
Tips
<C-u>is the complement of<C-w>— it deletes everything from the cursor back to the start of the line, which is useful when you want to retype an entire line from scratch<C-w>works in Vim's command-line mode too — press<C-w>while typing an Ex command to delete the last word- These shortcuts come from the Unix terminal (they work in bash and zsh as well), so muscle memory transfers between Vim and your shell
- The deleted text from
<C-w>is not placed into a named register — it is effectively discarded - If you delete too much with
<C-w>, press<C-u>to clear the rest and retype, or press<Esc>anduto undo the entire insert session - Combine with
<C-r>{register}to delete a word and immediately paste from a register in its place — all without leaving insert mode - For deleting a single character,
<C-h>(or Backspace) is faster than<C-w>— use<C-w>when you need to erase a whole word at once