vimtricks.wiki Concise Vim tricks, one at a time.

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
  1. Press A on line 1, type = true;, press <Esc>
  2. Press A on 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

Next

How do I ignore whitespace changes when using Vim's diff mode?