This article is part of the article series "Vim Plugins You Should Know About."
<- previous article next article ->
Vim Plugins, surround.vim

Here comes the second post in the article series "Vim Plugins You Should Know About". This time I am going to introduce you to a plugin called "repeat.vim".

Repeat.vim fixes an important functionality problem in the surround.vim plugin that I wrote about last week. The problem with surround.vim lies in the repeat command "." (dot). If you had applied a surrounding and wanted to repeat it with the "." command, it wouldn't work. This plugin fixes this problem.

So basically, whenever you install surround.vim, you also want to install repeat.vim with it.

There is one catch, though. It does not repeat visual or "ys" commands. Luckily, the "ys" commands can be often be substituted with "cs" commands. For example, if you wanted to do several "ysw"" (wrap a word in quotes), you may type "csw"" and then use "." commands to repeat. The only way to repeat visual commands is to record a macro.

Here is an example usage of the repeat.vim script. Suppose you had typed a sentence and you wanted to wrap all the words in quotes:

|foo bar baz quux muux woox

(| is cursor)

Type csw":

|"foo" bar baz quux muux woox

Now press W.

"foo" |"bar" baz quux muux woox

W moved to the next word and . repeated the wrapping command.

Now do the same 4 more times, and you have the whole line wrapped:

"foo" "bar" "baz" "quux" "muux" "woox"

How to install repeat.vim?

  • 1. Download repeat.vim to ~/.vim/plugin (on Unix/Linux), or ~\vimfiles\plugin (Windows).
  • 2. Restart Vim or source repeat.vim with ":so ~/.vim/plugin/repeat.vim" on Unix or ":so ~/vimfiles/plugin/repeat.vim" on Windows).

Have Fun!

Have fun with surround.vim + repeat.vim. I'll write about a much more life-changing plugin the next time. :)

This article is part of the article series "Vim Plugins You Should Know About."
<- previous article next article ->


December 16, 2008, 05:42

Note that you could also 'record' your actions. Something like this (borrowed from the Vim tips wiki):

qq            : record keystrokes to register q
... enter some commands...
q             : quit recording
@q            : execute commands again
@@            : repeat
paco Permalink
December 16, 2008, 09:53

Great tip, thanks !
Only one thing, in "How to install surround.vim?" section shouldn't say:

"Download repeat.vim to ~/.vim/plugin"

instead of

"Download repeat.vim to ~/.vim" ??

cheers !

December 16, 2008, 10:05

mileszs, thanks for the tip! Those are also called 'macros'.

paco, it sure should say so. Fixed. Thank you!

sathiya Permalink
December 19, 2008, 11:21

I think it should be
How to install repeat.vim?

instead of
How to install surround.vim?

is it ?

December 20, 2008, 23:01

sathiya, oops, sure is. corrected now.

abcuser Permalink
January 06, 2009, 16:34

I have been asking around how to add or remove comments (#) before multiple lines in vim program. This is useful if you have a bash script but would like to comment out multiple lines and vice versa.

There are the steps:
1. mark lines
2. execute: ,# to comment
or execute ,3 to uncomment (3 and # are on the same key).

Read more about it on Ubuntu forum where I was asking for help:

zebra24 Permalink
May 16, 2009, 00:07

foo bar baz quux muux woox
to get
“foo” “bar” “baz” “quux” “muux” “woox”

use this:


substitute "any word" with "\1".

You can also use c to confirm:

Chad Permalink
March 03, 2010, 17:40

@zebra24 : It's always helpful to have the regexp version for mass changes. Here's a few tricks to make that a little more palatable:

Very magic. eliminates lots of escaping by assuming the special nature of characters:


Given that we're taking the whole match, we can skip the grouping, and since we aren't matching on the whole word we can skip the word-delimiters:


Which is something that I might actually stand to use instead of the manual method. Patterns full of backslashes, especially, make my eyes bleed. Cheers!

Chad Permalink
March 03, 2010, 17:42

And of course I forgot to escape my angle bracket. That first pattern:

Ehtesh Choudhury Permalink
June 15, 2010, 17:01

I don't see why this isn't bundled with surround.vim, if it's a fix. Is there other functionality here that I'm missing where you would want repeat.vim by itself?

Although it does seem rather easy to implement it with other plugins for repeat functionality. Hrm... in that case, nevermind.

July 04, 2010, 20:32

Instead of installing repeat.vim I find it simpler to use macros -- record the keystrokes by pressing q, <the letter to store the macro in>, do whatever actions you want, and then q again to stop recording.

Then use @<letter> to run that macro; which can be repeated as required.

July 04, 2010, 20:33

The text in the angled brackets got a bit messed up: 'the' was 'actually the letter you want to store the macro in' and the @[letter]

July 04, 2010, 22:06

I fixed it, thanks.

Leave a new comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "0day_115": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.