vi and wrap text

Peder Blom peder.blom at bredband.net
Wed Oct 8 07:48:15 PDT 2003


On Wed, 8 Oct 2003 06:22:45 -0500
Bryan Cassidy <b_cassidy at bellsouth.net> wrote:

> I want to know is there a way to wrap the text in vi? In emacs you can
> just hit Esc+q and it will wrap the text. How about vi?

I dont use emacs, but isn't Esc+q the command to rewrap text? I'm not
aware of any such command in vi but instead you can invoke the external
command fmt.

To rewrap the whole text to 60 columns:

:%!fmt 60

To rewrap the text between lines 50 to 100:

:50,100!fmt 60

You can of course also set markers, say a and b, and then

:'a,'b!fmt 60


Check man fmt! It is capable of doing other things you might find
useful, like centering a piece of text.


(Hint: other useful external commands that can be used to extend vi in
this way includes expand, unexpand and awk, especially awk is very
powerful for advanced text processing. You can also write your own
shellscripts and programs, the possibilites are almost unlimited.)



More information about the freebsd-questions mailing list