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

How do I repeat the last Ex command I ran?

Answer

@:

Explanation

The @: command re-executes the most recently run Ex command (any command starting with :). This is incredibly useful when you need to run the same command repeatedly — stepping through quickfix entries, repeating a substitution on different lines, or reapplying a setting after switching buffers.

How it works

  • @: replays the last Ex command exactly as you typed it, including its range and flags
  • After running @: once, you can repeat it again with @@ (which repeats the last @{register} command)
  • This works because : is a read-only register that always holds the most recent Ex command

Example

Suppose you run a substitution on the current line:

:s/foo/bar/g

Now move to another line and press @: — the same substitution runs on that line. Move again, press @@ to repeat it even faster.

Or step through quickfix results manually:

:cnext

Press @: to jump to the next result, then @@ to keep going. Each press advances to the next entry.

Tips

  • After the first @:, use @@ for subsequent repeats — it's fewer keystrokes
  • @: is different from . (dot command): the dot repeats the last normal mode change, while @: repeats the last Ex command
  • Use @: with :bnext, :cnext, :lnext, or :tabnext to quickly cycle through buffers, quickfix entries, location list entries, or tabs
  • Combine a count with @: to repeat multiple times: 5@: runs the last Ex command five times
  • The : register is read-only — you can view its contents with :reg : or paste it with ":p
  • If you need to modify the command slightly before re-running, press :<Up> to recall it into the command line for editing instead

Next

How do I edit multiple lines at once using multiple cursors in Vim?