Productivity Boost with Vim

It is one of those moments when you realize that the few hours you spent learning a technology or actually tried to grok a book paid off and you reap the rewards of that investment. In particular, the technology happens to be vim. I am sure everybody’s favorite editor has this capability too, or something like that, or something fairly close, or even better – but the point I am trying to make here is that something that would have taken me half an hour previously took me 2 minutes to finish because I took the trouble to learn vim properly using Practical Vim.

Problem: Convert 25 citations from LaTeX format to Web format

Concretely, given several citations of the form

\item Author 1, Author 2, …, Author n, {\it Title of the Paper}, In Proceedings of Conference, Address, Year


<li><p>Author 1, Author 2, …, Author n, <font color=”darkred”>Title of the Paper</font>, In Proceedings of Conference, Address, Year</p></li>

So how do we do it? I did it in two steps.

[Step 1] Record a macro, perform adding <li><p> at the start and </p></li> at the end of each sentence, and repeat the macro for each sentence in parallel. Concretely,

qa0daWI<li><p><Esc>A</p></li><Esc>qjVG:norm @a

and there you have it!

[Step 2] Look for the regex that matches the tags around the titles of the papers, and then replace them with the desired text. Concretely (broken down into steps for clarity):

/\v\{\\it\_s(.*)}<Enter> (search for the pattern)

:%s//<font color=”darkred”>\1<\/font>/g<Enter> (reuse the pattern found in replacement)

And voilà, it works! Brilliant 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s