Sunday, March 15, 2009

vi is all you need!

vi is a great editor and I just want to say it out loud!

Learn to use it, learn to love it and then learn to enjoy it...

I constantly find myself typing ESC h,j,k,l don't you?

PS learn to use hjkl and not the arrows, it will help you when you get your shell to vi mode (set -o vi)

Learn the tricks, learn search/replace and other tools and you'll greatly enhance your job performance...

I currently have to edit a lot of SQL files and search/replace just saved me 4-5 days of typing (and who knows how many mistakes)...

a simple ESC
:% s/what am I changing/what the new text will be/g
is all it takes... (g is for global, so if you have more occurencies of the same text all will be changed)

good options to know are
:4,8 s/what/new/gc
which will only run from 4th to 8th line and ask you to approve every change

other regexp formats are also supported:
:% s/this line has \(first\) argument/here was the \1 argument/g

just to make sure you know which lines to include try:
:set nu
:set nonu