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?"

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

Comments

Add your own top of comment
Chuck's avatar

Just an additional note, you might ask the question “why not just use a standard text editor such as notepad?”, well as stephen said, he could go on and on. However, there is one simple thing that I found made a huge difference when hard coding using vim versus a standard text editor, and thats something as simple as changing the color scheme. Viewing black code on a white background day in day out can send you a bit boogly (I recommend using Vim’s “torte” colour scheme - pretty pretty colours!). Not to say that other programs dont offer this option, just another brownie point for Vim :)

Posted by Chuck  on  10/15  at  04:02 PM
bottom of comment

Add a Comment

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?

Please submit the word you see below: