I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

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. :)
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)

(3 votes, average: 4 out of 5)
|
|
|


December 16th, 2008 at 5:42 am
Note that you could also ‘record’ your actions. Something like this (borrowed from the Vim tips wiki):
December 16th, 2008 at 9:53 am
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 16th, 2008 at 10:05 am
mileszs, thanks for the tip! Those are also called ‘macros’.
paco, it sure should say so. Fixed. Thank you!
December 19th, 2008 at 11:21 am
I think it should be
How to install repeat.vim?
instead of
How to install surround.vim?
is it ?
December 20th, 2008 at 11:01 pm
sathiya, oops, sure is. corrected now.
January 6th, 2009 at 4:34 pm
Hi,
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:
http://ubuntuforums.org/showthread.php?t=896481&highlight=vim
February 6th, 2009 at 5:09 pm
[…] If you are intrigued by this topic, I suggest that you subscribe to my posts! For the introduction and first post in this article series, follow this link - Vim Plugins You Should Know About, Part I: surround.vim. Part II is here: repeat.vim. […]
May 16th, 2009 at 12:07 am
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:
August 14th, 2009 at 7:34 pm
[…] Vim Plugins You Should Know About, Part II: repeat.vim: http://www.catonmat.net/blog/vim-plugins-repeat-vim/ […]
January 18th, 2010 at 2:57 pm
[…] Part II: repeat.vim - repeat the previous surrounding command. […]
March 3rd, 2010 at 5:40 pm
@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!
March 3rd, 2010 at 5:42 pm
And of course I forgot to escape my angle bracket. That first pattern: