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

How do I access the last Ex command I ran?

Answer

":

Explanation

The : register contains the last Ex command that was executed. You can paste it or use it in macros.

How it works

  • ": stores the most recent : command
  • ":p pastes the last command into the buffer
  • @: executes the last command again
  • The register is read-only

Example

After running :sort, the : register contains sort. Pressing @: repeats the sort command.

Tips

  • @: is one of the most useful register commands
  • @@ repeats the last @ command (including @:)
  • <C-r>: pastes the last command in insert mode
  • In command-line mode, the up arrow also recalls previous commands
  • : register updates with every Ex command you run

Next

How do you yank a single word into a named register?