How do I re-insert the text from my last insert session and immediately return to normal mode?
Answer
<C-@>
Explanation
Pressing <C-@> (Ctrl + @, which is the NUL character) in insert mode inserts the same text that was typed during the most recent insert session, then immediately returns to Normal mode. It is the one-shot sibling of <C-a>, which inserts the same text but stays in insert mode.
This is especially handy when you need to repeat a previously typed snippet exactly once and move on, without the extra <Esc> press that <C-a> requires.
How it works
<C-a>in insert mode — inserts last inserted text, stays in insert mode<C-@>in insert mode — inserts last inserted text, exits to Normal mode immediately- Both use Vim's internal
.(dot) insertion register to recall what was typed - The "last inserted text" is reset each time you exit and re-enter insert mode
Example
You enter insert mode and type a comment header:
-- Section: Authentication
Then press <Esc>. Later, on another line, you enter insert mode and press <C-@>. Vim inserts:
-- Section: Authentication
and drops back to Normal mode in one keystroke, equivalent to <C-a><Esc> but faster.
Tips
- In many terminal emulators,
Ctrl+@orCtrl+2sends the NUL character that Vim maps to<C-@> - Works well for repeated boilerplate: enter a template once, then
<C-@>to stamp it elsewhere - If you need to re-insert text without exiting Normal mode first, yank with
".and paste withpinstead