formatting text from within vi

Bill Campbell freebsd at celestial.com
Sat Feb 11 12:27:28 PST 2006


On Sat, Feb 11, 2006, David Banning wrote:
>I am familiar with the !}fmt used in vi to reformat a paragraph, but
>I wondered how, or if it is possible to do more complex formatting. 

You can format any line or block of text in vi(m) by passing it through an
arbitrary filter program.

I have this line in my ~/.vimrc file which formats whatever paragraph the
cursor is in by running through a script I wrote that formats its standard
using ``groff -mm''.  The ``{'' positions the cursor at the beginning of
the paragraph and the ``!}'' says filter to the end of the paragraph.

map <F5> {!}gfmt

You can also type a command on a line, and execute it replacing the
contents of the line with the output of the program.  If I want to get
copies of all my signature files containing the text ``democracy'' I could
enter the following line, place the cursor somplace in that line, and press
``!!sh<RETURN>''.

cat `grep -li democracy ~/.signature.*`

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Those who profess to favor freedom, and yet depreciate agitation, are
men who want rain without thunder and lightning.  They want the ocean
without the roar of its many waters.
                -- Frederick Douglass


More information about the freebsd-questions mailing list