The more I learn about vi the better it becomes.

Just to pass along a couple of tricks I recently learned about vi (vim)
which have made a huge difference in my use of it.

A big problem with vi is fixing up those ragged lines after you edit a
paragraph. You can just pass the lines through a filter fmt and it fixes
that right up. Just position your cursor in the paragraph you want to fix
up, and have a blank line at the end and the beginning of the paragraph,
(Blank lines separate paragraphs as far as I can tell.)

 {!}fmt [return]

If you don't like the result, just press u.  Man fmt has some options
to read about.  Just map this to the g or other unused key for fast
work. If you want to format the whole document like this, not just the
paragraph you are in, change the command to:

 1G!Gfmt [return]

Remember, have blank lines between paragraphs.  Combined with the J
command to join lines, this make formatting a document with vi almost fun
and very fast. If you want to get rid of those extra blank lines between
paragraphs after you are all done formatting, the following works well:

 1G!Gsed "/^$/d"

You can also run this command in ex mode like this.

 :1,$ ! sed "/^$/d"

This make re-editing the command to fix mistakes easier. Recall the
command with :[uparrow].

Joel
_______________________________________________
Linux-users mailing list
Archives, Digests, etc at http://linux.nf/mailman/listinfo/linux-users

Reply via email to