[comp.unix.questions] vi format command

sct@alpha.lanl.gov (Stephen Tenbrink) (09/12/89)

Is there a technique for reformatting a paragraph when using vi?  Sometimes
when one has deleted and added text to a paragraph the lines no longer end
near the right side of the screen.  Some editors such as EDT have a
technique of selecting the whole paragraph and then entering a command to
reformat the whole paragraph.  The word wrap margin is used to set the
right hand margin.

I'm sure there is a way to do this easier than inserting 'returns' and
using the 'J' command.  Does anyone have an answer?

rock%warp@Sun.COM (Bill Petro) (09/12/89)

sct@alpha.lanl.gov (Stephen Tenbrink) writes:

>Is there a technique for reformatting a paragraph when using vi?  Sometimes
>when one has deleted and added text to a paragraph the lines no longer end
>near the right side of the screen.  Some editors such as EDT have a
>technique of selecting the whole paragraph and then entering a command to
>reformat the whole paragraph.  The word wrap margin is used to set the
>right hand margin.

>I'm sure there is a way to do this easier than inserting 'returns' and
>using the 'J' command.  Does anyone have an answer?

" at top of paragraph, format this paragraph
!} fmt -c

" for the whole file, format all paragraphs
!G fmt -c

"from here to the end of the file, format all paragraphs
!$ fmt -c

" from anwhere in the paragraph, format this paragraph
{!}fmt -c


Here's how I map them in my .exrc file:
map @f !} fmt -c^M
map @F !G fmt -c^M
map ^Xf !$ fmt -c^M
map ^XF {!}fmt -c^M}^M

P.S. the -c option to fmt is for "crown" formatting, preserving the
indention of the first 2 lines within a paragraph.  You can leave it
off.


     Bill Petro  {decwrl,hplabs,ucbvax}!sun!Eng!rock
"UNIX for the sake of the kingdom of heaven"  Matthew 19:12

irf@kuling.UUCP (Bo Thide') (09/12/89)

In article <964@alpha.lanl.gov> sct@alpha.lanl.gov (Stephen Tenbrink) writes:
>Is there a technique for reformatting a paragraph when using vi?  Sometimes
>[text deleted]

Remember that you can filter your vi text through *any* filter/command
you have available on your system.  For instance, I very often reformat
my paragraphs by moving to the start of the paragraph (vi command '{')
and the I type '!}adjust' and the paragraph gets formatted.  If I instead
type '!}adjust -j' I get the paragraph right hand justified (non-ragged).

-Bo

gs26@prism.gatech.EDU (Glenn R. Stone) (09/12/89)

In article <124483@sun.Eng.Sun.COM> rock%warp@Sun.COM (Bill Petro) writes:
>sct@alpha.lanl.gov (Stephen Tenbrink) writes:
>>Is there a technique for reformatting a paragraph when using vi?  
> [lots of good answers deleted]

I've seen this discussion at least twice in the past two months.... is it
time to add this one to the "List of Frequently Asked Questions"?

In support of increased Signal/Noise ratios...

Glenn R. Stone
gs26@prism.gatech.edu, CCASTGS@GITNVE2.BITNET, ...!gatech!gitpyr!ccastgs
Box 30372, Atlanta, GA 30332

mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) (09/13/89)

Steven,

	I do the following:
{		- go to the beginning of the current paragraph
}!fmt -80	- reformat current para. w/ line length 80 (default is 72)

			Mike Chinni
			mchinni@pica.army.mil

merrell@data.mrc.uidaho.edu (09/14/89)

> The examples given in a response to this query, using the "fmt" command,
> look to be very good. Unfortunately, they also seem to be BSD-specific.
> I can find "fmt" in my BSD manuals, but there's no sign of it on our
> SysV Unisys systems. There IS a "newform" command under SysV, but it 
> doesn't appear to do what is needed -- it seems to work on a line-at-a-time
> basis, and does not appear to have any options that would cause it to
> work for reformatting whole paragraphs or larger text chunks.
> 
> Does anyone out there have a SysV solution to this question?
> 
> Regards, Will Martin

I use the same thing, but with "adjust".  adjust works on larger chunks;
looks, like similar options too.  It's a simple formatter, not meant to be
anything fancy (like nroff or troff).  This is on HP-UX 6.5.


Randy Merrell
Microelectronics Research Center         "Rejoice in the Lord always;
College of Engineering                      again I say, rejoice!"
University of Idaho                              -- Phil. 4:4
Moscow, ID  83843
-----------------------------------
UUCP:     ucdavis!egg-id!ui3!rmerrell
BITNET:   rmerrell@groucho.mrc.uidaho.edu
INTERNET: rmerrell@groucho.mrc.uidaho.edu

wmartin@stl-06sima.army.mil (Will Martin) (09/14/89)

Just as a brief follow-up to my query about doing the "quick formatting"
under Sys V instead of using the BSD-specific "fmt" command: I was just
told about a locally-available public-domain formatter called "ff" that
does this, and I've tested it and it works. However, this is NOT
anything standard available under Sys V. [There IS a Sys V "ff" command
but that is something totally different that is a 1M admin command, BTW.]

The "ff" formatter man page indicates that it came from Gary Perlman
[et al] back in 1985 or thereabouts; the institution is unknown.

It still would be nice if there was a standard way under Sys V to do
this, without having to incorporate products from other sources. The
reference to "adjust" by another respondent appears to be something
unique to his system, or HP's UNIX version, or the like; it isn't here
(on a Unisys Sys V UNIX).

Regards, Will Martin

artp@motbos.UUCP (Art Parmet) (09/15/89)

In article <964@alpha.lanl.gov>, sct@alpha.lanl.gov (Stephen Tenbrink) writes:
> Is there a technique for reformatting a paragraph when using vi?  Sometimes
....

There  is  a  public  domain program called "fill" which will do exactly
what you want.  By compiling it with the "justify" option as the default
and naming it with a one letter command (like "f"),  you  can  format  a
paragraph  from  the current cursor position to the end of the paragraph
by:      !}f

The source is yours on reauest.

Regards,
Art
-------------------------------- 

<< Unusual Disclaimer >>

Art Parmet - Northeast Area Eng Mgr @ Motorola Semiconductor, Woburn, Ma.
UUCP: {hplabs!motsj1,decwrl!decvax,gatech!mcdchg,apollo,oakhill}..!motbos!artp

Voice: +1 617-932-9700  Fax: +1 617-932-9100