January 28, 2007

VIM 7

Category: VI — Raffael Marty @ 7:01 pm
I haven’t written about VIM in a long time. Although I am using the editor daily. Finally, I fixed some HTML errors on the VIM page and added some comments about the new features in Version 7 of VIM.
December 6, 2005

Adding Random Data To Files

Category: VI — Raffael Marty @ 1:30 am

I find myself adding data to files that need to be randomized. Well, just call awk from within vi and use the rand() function

:%!awk ‘BEGIN {srand()}; {if (int(rand()*4)==2) {printf(“\%s,S\n”,$0)} else print $0;}’

Maybe even a bit more comfortable AND this only adds to the lines if they don’t use SA, S or F

:%!awk ‘BEGIN {srand()} \!/(SA|S|F)$/ {if (int(rand()*4)==2) {sub(/$/,”FA”);}};{print}’

Adding Text To Special Lines

Category: VI — Raffael Marty @ 1:22 am

I need to remember this one:

:g/some text/s/$/,more_data

This will add another column of data to all the lines with “some text”. Simple but useful.