How do I re-insert the text I typed in the previous insert session?
Answer
<C-a> (insert mode)
Explanation
While in insert mode, pressing <C-a> re-inserts the exact text you typed during your previous insert session. It is the insert-mode equivalent of the . normal-mode repeat command, but specifically for text insertion.
How it works
<C-a>— in insert mode, inserts the same text that was inserted last time you left insert mode- This is different from
<C-r>.which pastes the.(dot) register —<C-a>is a dedicated binding - The previous insert text is also accessible as the
"register (the unnamed register preserves the last insert)
A related command: <C-@> (Ctrl+@, which may appear as <C-Space> in some terminals) does the same thing as <C-a> but then immediately exits insert mode.
Example
You type on one line:
function handleError(err) {
You press <Esc>, move to the next blank line, press i to enter insert mode, then press <C-a>. The same text is inserted again:
function handleError(err) {
function handleError(err) {
Tips
- Useful when you need to repeat a complex insert that
.cannot replicate (e.g., if you moved between inserts) - Unlike
.,<C-a>inserts only the text — it does not repeat any leading motion - To check what text will be reinserted, use
:reg .to inspect the dot register