Thursday, October 30, 2008

General: Using VI to Insert String Before a Line and Append Strings After a Line

I am an avid supporter of VI in the tex editor wars. Always have, always will. With that said, I have to admit, I was a bit embarrassed when I needed to a simple task of adding a string to the front and end of a whole list of lines (tables names I had pulled from a database) and I couldn’t remember the VI commands to do so. What I needed was to add “drop table “ and “;” to the front and end of each line, respectively. The commands I ended up using were:

:1,$s/ ^ /drop table /
:1,$s/$ / ; /

Strange, I’ve been using VI for years, and never needed to do that before. I am so used to my small set of commands, I never bothered to expand out and learn everything else that VI could do.

Here is a list of sites that have useful VI commands, shortcuts, and tutorials:
http://andrewfraser.wordpress.com/2007/01/12/useful-simple-vi-commands-for-dbas/
http://www.viemu.com/vi-vim-cheat-sheet.gif
http://tnerual.eriogerg.free.fr/vimqrc.pdf
http://www.eng.hawaii.edu/Tutor/vi.html#modes

1 comment:

Anonymous said...

Thanks !!