How do I quickly re-insert the text I just typed without leaving insert mode?
Answer
<C-a> (in insert mode)
Explanation
While in insert mode, pressing <C-a> re-inserts whatever text you typed during your previous insert session. This is the text that was entered between entering insert mode and pressing <Esc>. It is a fast way to duplicate your last typed text without switching modes or using registers.
How it works
- Enter insert mode (e.g., with
i,a,o, etc.) and type some text - Press
<Esc>to return to normal mode - Enter insert mode again at a new position
- Press
<C-a>to re-insert the previously typed text at the cursor
The text comes from the ". register (the last inserted text register), which Vim updates every time you leave insert mode.
Example
Starting with:
foo
bar
- Press
Aon line 1, type= true;, press<Esc> - Press
Aon line 2, then press<C-a>
Result:
foo = true;
bar = true;
Tips
<C-@>does the same thing but also exits insert mode after inserting the text- This only remembers text from the most recent insert session — starting a new insert clears the previous one
- For more control, use
<C-r>.to paste from the insert register explicitly