Applications


August 09, 2006

Tools: Vim

Hey there. I’ve been asked by my supreme ruler to write something for this weblog. So technically I’m now being paid to write for a weblog, and they said it would take talent for that (in your face “Dooce”:http://www.dooce.com, “Kottke”:http://www.kottke.org and “Gruber”:http://daringfireball.net/).

So, I rumbled about a little in my branes and came up with this, talk about the stuff I use to do my job, maybe someone else in here will do the same. The developers need me a lot to do their job so maybe they’ll have a post entitled “Tools: Stephen”.

Onward. “Vim”:http://www.vim.org/ is Vi improved (that’s all the history you’re getting, feel free to read about it on the Vim website though), a text editor to beat all, a tool of precision and consequently steep learning curve. This is likely to bore most of you rigid, there’s no fancy Flash/JavaScript flashing bells here, sorry.

With Vim, finding stuff is easy:

/monkeys

Simple, takes you to the first occurence of start of the string ‘monkeys’ in the current file. Hit ‘n’ to go the next occurence and ‘N’ to the previous.

/monkeys/e

Takes you to the end of the first occurence of the string ‘monkeys’, add /e+n to take you to the end of match plus n. adding /s+n instead does the same but at start of string.

Replacing stuff is easy too:

:s/monkeys/peanuts/

...replaces the first occurence of the word ‘monkeys’ with ‘peanuts’ on the current line

:s/monkeys/peanuts/g

...replaces all occurences of ‘monkeys’ on the current line with ‘peanuts’

:%s/monkeys/peanuts/g

...replaces all ‘monkeys’ with ‘peanuts’ in the file.

I could go on, and on, and on, and on. You can do these simple things on many files at once and you can do many more complex things with regular expressions, in fact you can do all sorts of great text editor things and you can do them quickly on Windows (GVim), Mac or Unix. *Vim rocks!*

vim -c ":%s%s*%Zru)unzrfvgr[terra.pnevfraqn.pbz%|:%s)[[()])-)Ig|norm Vg?"

Read more...
Posted by Andrew on 08/09 at 12:07 PM | category: Applications (1) Comments