If you like my blog, I'd be thankful for a gift from my Amazon Wishlist.

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. :)



Twitter
Facebook
Plurk
more
GitHub
LinkedIn
FriendFeed
Google Buzz
irc.freenode.net, channel #catonmat
Comments
Note that you could also 'record' your actions. Something like this (borrowed from the Vim tips wiki):
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 !
mileszs, thanks for the tip! Those are also called 'macros'.
paco, it sure should say so. Fixed. Thank you!
I think it should be
How to install repeat.vim?
instead of
How to install surround.vim?
is it ?
sathiya, oops, sure is. corrected now.
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
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:
@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!
And of course I forgot to escape my angle bracket. That first pattern:
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.
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.
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]
I fixed it, thanks.
Leave a new comment