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

How do I make plugin actions repeatable with the dot command in Vim?

Answer

vim-repeat

Explanation

The vim-repeat plugin by Tim Pope extends Vim's built-in . (dot) command so it works with plugin mappings. Normally, . only repeats native Vim operations — it has no awareness of multi-step plugin actions. With vim-repeat installed, plugins that integrate with it (like vim-surround, vim-commentary, and vim-unimpaired) become fully repeatable with a single . press.

The problem

Without vim-repeat, pressing . after a plugin action like cs"' (change surrounding double quotes to single quotes via vim-surround) would only repeat the last native Vim command within the plugin's implementation — not the full surround operation. The result is usually broken or unexpected.

How it works

Install vim-repeat alongside your other plugins. There is no configuration required. Plugins that support it automatically register their mappings with vim-repeat, and . just works.

" Example workflow with vim-surround + vim-repeat:

" 1. Change double quotes to single quotes on the first string:
cs"'

" 2. Move to the next string and press dot to repeat:
.

" 3. Move to another string and repeat again:
.

Plugins that support vim-repeat

Most Tim Pope plugins and many popular third-party plugins integrate with vim-repeat out of the box:

  • vim-surroundds, cs, and ys commands become repeatable
  • vim-commentarygcc and gc{motion} become repeatable
  • vim-unimpaired — bracket mappings like [e and ]e become repeatable
  • vim-abolish — case coercion commands like crs and crc become repeatable
  • vim-exchangecx{motion} becomes repeatable
  • vim-easyclip — substitution and move operations become repeatable

For plugin authors

If you write your own plugin mappings, you can make them repeatable by calling repeat#set() at the end of your mapping:

silent! call repeat#set("\<Plug>MyPluginAction", v:count)

This tells vim-repeat which mapping to replay when the user presses ..

Tips

  • vim-repeat is a silent dependency — it has no commands or mappings of its own, it simply enhances .
  • Install it early in your plugin setup since many plugins check for its presence at load time
  • Without vim-repeat, some plugin actions may appear to work with . but produce subtly wrong results — installing it eliminates an entire class of confusing bugs
  • Works with both Vim and Neovim with no additional configuration

Next

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