[comp.editors] Reformatting in vi

cfj@nonvon.uucp (Charles Judson) (01/20/88)

When editing with vi is there a "paragraph reform" capability similar to 
Control-b in Wordstar?  If I insert a sentence or otherwise garble the 
line length I'm only able to fix it manually by inserting carriage
returns at the proper places thru the end of the paragraph.  Suggestions
as to a better way would be gratefully appreciated.
-- 

  Charles Judson       ...!ptsfa!nonvon!cfj

jmc@ptsfa.UUCP (Jerry Carlin) (01/21/88)

In article <1988Jan19.102343.3255@nonvon.uucp> cfj@nonvon.UUCP (Charlie Judson) writes:
>When editing with vi is there a "paragraph reform" capability ...

UNIX/WORLD's December 1986 issue had source code to a paragraph reformatter
in Dr. Rebecca Thomas's column "Holiday Gifts for the Grabbag".

-- 
Jerry Carlin (415) 823-2441 {ihnp4,lll-crg,ames,qantel,pyramid}!ptsfa!jmc
soon: {ihnp4,lll-crg,ames,qantel,pyramid}!pacbell!ptsfa!jmc
To dream the impossible dream. To fight the unbeatable foe.

andrea@hp-sdd.HP.COM (Andrea K. Frankel) (01/22/88)

I have the following in my .login (I broke this up so it would mail
properly - remove all linebreaks):

setenv EXINIT 'set redraw noslow beautify open wm=8 report=2 shell=/bin/csh
|map * {!}fmt
|map v :1,$s/^/>/
|map q :r ~/.net.signature

The first map lets me hit "*" from anywhere in a paragraph, and the
whole paragraph will be reformatted.  I use this so often, it's a real
bother when I'm working with somebody else who doesn't have this set up!
The second map is for quoting the article you're responding to on news,
and the last is because we don't have anything that automatically
appends a signature file.

Hope this helps...

Andrea Frankel, Hewlett-Packard (San Diego Division) (619) 592-4664
                "...like a song that's born to soar the sky"
______________________________________________________________________________
UUCP     : ...hplabs!hp-sdd!andrea from 
	   {ihnp4|cbosgd|allegra|decvax|gatech|sun|tektronix}
           or ...hp-sdd!andrea from {hp-pcd|hpfcla|hpda|noscvax|gould9|sdcsvax}
Internet : andrea%hp-sdd@ {nosc.mil | sdcsvax.ucsd.edu | hplabs.HP.com}
CSNET    : andrea%hp-sdd@hplabs.csnet
USnail   : 16399 W. Bernardo Drive, San Diego CA 92127-1899 USA

syd@dsinc.UUCP (Syd Weinstein) (01/22/88)

In article <1988Jan19.102343.3255@nonvon.uucp> cfj@nonvon.UUCP (Charlie Judson) writes:
>
>When editing with vi is there a "paragraph reform" capability similar to 
>Control-b in Wordstar?  If I insert a sentence or otherwise garble the 
>line length I'm only able to fix it manually by inserting carriage
>returns at the proper places thru the end of the paragraph.  Suggestions
>as to a better way would be gratefully appreciated.
>-- 
>
>  Charles Judson       ...!ptsfa!nonvon!cfj

When I am using vi to enter long text documents, and yes, I do use vi
to enter long text documents, I set one of my function keys to be
remapped to !}fmt^M and then when I use that key it sends the text
from current line to end of paragraph to the fmt program and takes the
result back and replaces the text with it.

fmt is a utility I found on an old usenix tape, could even be a bsd
utility.  All it does is reword wrap the lines.  It does the job you
ask real well.  However, I do find it necessary sometimes to redefine
then end of paragraph string in vi to include tables and my special
local macros.

-- 
=====================================================================
Sydney S. Weinstein, CDP, CCP
Datacomp Systems, Inc.				Voice: (215) 947-9900
{allegra,bellcore,bpa,vu-vlsi}!dsinc!syd	FAX:   (215) 938-0235

pcm@iwarpo3.intel.com (Phil C. Miller) (01/22/88)

In article <1988Jan19.102343.3255@nonvon.uucp> cfj@nonvon.UUCP (Charlie Judson) writes:
>
>When editing with vi is there a "paragraph reform" capability similar to 
>Control-b in Wordstar?

In vi there is a mechanism for passing paragraphs to a simple text formatter
called fmt.  This utility simply does a 'fill' operation; that is, adds text
on a line until the line is full, then start the next line, etc.  This 
mechanism, when used in conjunction with with the J(oin) command, provides
a rudimentary capability which will do what you want.

You invoke this mechanism by typing:
!}fmt
This can be interpreted as follows:
   !       escapes the editor and invokes a Unix shell;
   }       indicates a paragraph-level entity is to be
           passed as standard input to the shell command;
   fmt     is the shell command to which the paragraph is
           to be passed, and which does the reformatting.

Vi somehow magically substitutes the new, reformatted text for the old, 
unformatted text in your edit file.

>  Charles Judson       ...!ptsfa!nonvon!cfj

kevin@ttidca.TTI.COM (Kevin Carothers) (01/22/88)

  Charles Judson       ...!ptsfa!nonvon!cfj

     (original text follows...)
->When editing with vi is there a "paragraph reform" capability similar to 
->Control-b in Wordstar?  If I insert a sentence or otherwise garble the 
->line length I'm only able to fix it manually by inserting carriage
->returns at the proper places thru the end of the paragraph.  Suggestions
->as to a better way would be gratefully appreciated.


----------
Watch my fingers carefully, and do the following steps:

step 1.   Mark The beginning of the paragraph with a ":ka".

step 2.   Position to the last line of the paragraph, and type in the
          following character sequence *EXACTLY*:

                !'anroff

     You should get the following *INSERTED* at marker position 
     "a";

When editing with vi is there  a  "paragraph  reform"  capability
similar to Control-b in Wordstar?  If I insert a sentence or oth-
erwise garble the line length I'm only able to fix it manually by
inserting  carriage  returns at the proper places thru the end of
the paragraph.  Suggestions as to a better way would be grateful-
ly appreciated.

                             CAVEAT
                             ======
     You'll also get a page-full of empty lines. But hey, It beats
     doing what you were doing before, right?

NOW ---
For all you 'nroff' gurus out there;

     I can't seem to get nroff to  keep from inserting all those lines of
     blank stuff in my buffer. Any suggestions?


P.S.
====
If you want, you could preceed each paragraph with a ".PP", and
enter the "bang" command as follows;

              !'anroff -ms

This will format a bunch of paragraphs in succession. Use at your
own discretion. Advised that you bone up on some nroff documentation
if you carry this activity to extremes.


Viva Vi!


Kevin


[...sign here]!{csun,psivax,rdlvax,trwrb,...to name a few}!ttidca!kevin





     

kevin@ttidca.TTI.COM (Kevin Carothers) (01/23/88)

Time to  follow up on my own posting. 

In my response  to paragraph reformatting inside vi, the technique
I described inserted a page-full of blank lines inside the message text.
I've since been fiddling with it, and have found that if you define a
".pl n" at the first line of your paragraph, with 'n' being the
approximate length in inches of the paragraph, it will cut the number
of blank lines out.  

To rehash what the entire sequence of steps is, I'll use my own 
paragraph above as an example;

(...original text, preceeded by a ".pl 2")
.pl 2
In my response  to paragraph reformatting inside vi, the technique
I described inserted a page-full of blank lines inside the message text.
I've since been fiddling with it, and have found that if you define a
".pl n" at the first line of your paragraph, with 'n' being the
approximate length in inches of the paragraph, it will cut the number
of blank lines out.  

     By marking the '.pl 2' line with ":ka<cr>", and entering 
     the command sequence;
              !'anroff 

 The paragraph is reformatted as;

In my response  to paragraph reformatting inside  vi,  the  tech-
nique  I described inserted a page-full of blank lines inside the
message text.  I've since been fiddling with it, and  have  found
that if you define a ".pl n" at the first line of your paragraph,
with 'n' being the approximate length in inches of the paragraph,
it will cut the number of blank lines out.


...With only a *few* blank lines.

P.S.
Many Thanks to the poster of the original  question. Vi is an editor
which gets so much bad press that I always relish getting a chance to 
show what it can really do.



Kevin


[...sign here]!{csun,psivax,rdlvax,trwrb,...to name a few}!ttidca!kevin

jim@xanth.cs.odu.edu (Jim Duncan) (01/27/88)

In article <1726@ttidca.TTI.COM> kevin@ttidcb.tti.com (Kevin Carothers) writes:
>
>Time to  follow up on my own posting. 
>
>In my response  to paragraph reformatting inside vi, the technique
>I described inserted a page-full of blank lines inside the message text.
>
> (deleted many lines containing many steps, and many, many keystrokes...)
>
>P.S.
>Many Thanks to the poster of the original  question. Vi is an editor
>which gets so much bad press that I always relish getting a chance to 
>show what it can really do.
>

While it's true that vi gets a lot of bad (read "undeserved") press, I would
*not* consider this a shining example of its power.  In GNU Emacs, one moves
the point into the paragraph to be filled (assuming fill-mode is on), and
types ESC q to reformat the paragraph.  *No* blank lines are inserted.

Nonetheless, I have saved this gem for future reference.  Thanks for posting.

	Jim Duncan	jim@xanth.cs.odu.edu	..!sun!xanth!jim
-- 
 Jim Duncan, Computer Science Dept, Old Dominion Univ, Norfolk VA 23529-0162
 (804)440-3915     INET: jim@xanth.cs.odu.edu    UUCP: ...!sun!xanth!jim
 ---------- Time flies like the wind, but fruit flies like bananas. ---------

kevin@ttidca.TTI.COM (Kevin Carothers) (01/29/88)

>While it's true that vi gets a lot of bad (read "undeserved") press, I would
>*not* consider this a shining example of its power.  In GNU Emacs, one moves
>the point into the paragraph to be filled (assuming fill-mode is on), and
>types ESC q to reformat the paragraph.  *No* blank lines are inserted.


Well. Forgive me if I'm adding to the  noise  ratio  on  the
net, but if I may discuss what I think about vi's "power".

One thing that makes vi "powerful" on UNIX is that  it's  as
closely  coupled  with  UNIX as "csh".  That is, whether one
decides to format with "nroff", "fmt", or his/her  own  text
pre-processor,  it's  totally  possible,  and just a command
line away. For instance.  If you want to  find the number of
lines between two marks in a file,  you can use unix to find 
it for you, like;
                              :'a,'bw !wc -l


Sure, a lot of text editors have a feature or two  for  mas-
saging  a  paragraph or a margin. But  it's about useless if
it's not *exactly* what you need/want. Why have a  bunch  of
paragraph  formatters  around  when  mastery of one would be
much more desireable?  The beauty of  vi  that I  stress  to
people  who  don't  learn  it  (or don't think they have the
patience to) is that you can  take advantage of  just  about
everything UNIX has to offer *INSIDE* the editor.

Maybe that's possible with EMACS, or what have you, but  not
all  systems  I've  worked on have EMACS, JOVE, Rand "e", or
whatever.  I think (...just my opinion  mind  you)  that  an
understanding  of  vi is as necessary as an understanding of
shell programming to have a good knowledge of how UNIX works
(...time to get my asbestos 3-pc suite).



Kevin


:wq!

reeder@littlei.UUCP (reeder) (01/30/88)

Everyone has been talking about a paragraph formatting utility.  Well
here one is.  The comments should explain it all.  I have run this on
XENIX and BSC systems.  Enjoy!

/*
 * Paragraph reformating utility from UNIX/Word Magazine Nov. '85
 * Modified by Ed Reeder to allow for indentation, variable tabsize,
 * line width, and BSD operation.
 *
 * This is best used within the vi editor, e.g.,
 *	!}rfm
 *
 * To allow for 1-key reformatting within vi, put the following
 * in your /.exrc:
 * 	map #1 !}rfm^V^M
 * 	map #2 !}rfm^V^M}j
 *
 * This allows:
 * Function Key 1 to reformat a paragraph, with the cursor placed
 * 	at the beginning of the paragraph.
 * Function Key 2 to reformat a paragraph, with the cursor placed
 *	at the beginning of the next paragraph.
 *
 * NOTE: for this to work you must have your function keys defined
 *	in your TERMCAP entry.
 *
 * By default rfm will assume that Tabs represent 8 characters and
 * that the maximum line width will be 72 characters.  These can be
 * changed by specifying new values to rfm:
 *	rfm [-t tabsize] [-w width]
 */

#include "stdio.h"
#include <ctype.h>

#define YES 1
#define NO  0
#define LINELENGTH 72
#define TABSIZE 8	/* Number of characters a tab represents */
#ifdef bsd
#define STRCHR index	/* Library routine to find 1st occurrence of a char */
#else
#define STRCHR strchr	/* Library routine to find 1st occurrence of a char */
#endif

int	c;

main( argc, argv )
int	argc;
char	*argv[];
{
	int	endchar;	/* Does this word end a sentence? */
	int	getword();	/* Get next word on stdin */
	int	length;		/* Length of word read by getword */
	int	count;		/* number of characters on line so far */
	int	iindex = 0;	/* number of chars in 'indentation' */
	int	icount = 0;	/* number of apparent chars in 'indentation' */
	int	i;
	int	endwhile = 0;
	int	errflag = 0;
	int	tabsize = TABSIZE;
	int	linelength = LINELENGTH;
	int	strlen();
	int	printf();
	int	getopt();
	char	*strcat();
	char	*strcpy();
	char	word[255];	/* word read from stdin */
	char	istring[255];	/* indentation string */
	char	line[255];	/* output line */

	extern	int	optind;
	extern	char	*optarg;

	/*
	 * Get any options
	 */
	while(( c = getopt( argc, argv, "t:w:" )) != EOF )
		switch( c ) {
		case 't':
			for( i=0; optarg[i] != '\0'; i++ )
				if( isdigit( optarg[i] ) == 0 )
					errflag++;
			if( errflag )
				break;
			tabsize = atoi( optarg );
			break;
		case 'w':
			for( i=0; optarg[i] != '\0'; i++ )
				if( isdigit( optarg[i] ) == 0 )
					errflag++;
			if( errflag )
				break;
			linelength = atoi( optarg );
			break;
		case '?':
			errflag++;
		}
	if( errflag ) {
		fprintf( stderr, "usage: %s [-t tabsize] [-w width]\n", argv[0] );
		fprintf( stderr, "Defaults: tabsize=8,   width=72\n" );
		exit( 1 );
	}

	/*
	 * Let first line of non-white input define the level of indentation
	 */
	while(( c = getchar( )) != EOF ) {
		switch( c ) {
			/* Capture leading white space */
			case '\t':
				istring[iindex++] = c;
				/* for tab allow for mixed tabs and spaces */
				icount = ((icount / tabsize) * tabsize) + tabsize;
				break;
			case ' ':
				istring[iindex++] = c;
				icount++;
				break;
			/* Line was all white, reset indent info. */
			case '\n':
				putchar( '\n' );
				iindex = icount = 0;
				break;
			/* Found 1st non-white character, sets indendentation */
			default:
				istring[iindex] = '\0';
				count = icount;
				ungetc( c, stdin ); /* push this char back */
				strcpy( line, istring ); /* copy indent */
				endwhile++;
		}
		if( endwhile != 0 )
			break;
	}

	/*
	 * Main reformatting logic
	 */
	while(( endchar = getword( word )) != EOF ) {
		count += length = strlen( word );
		if( count > linelength ) { /* split the line here */
			count = strlen( line ); /* remove trailing blanks */
			while( line[--count] == ' ' )
				line[count] = '\0';
			printf( "%s\n", line );
			count = length + icount; /* begin count for next line */
			strcpy( line, istring );
			strcat( line, word );
			strcat( line, " " );
			if( endchar == YES )
				strcat( line, " " ); /* end of sentence space */
		}
		else if( endchar == YES ) {
			strcat( line, word );	/* print an extra space */
			strcat( line, "  " );
			count++;	/* to account for the extra space */
		}
		else {
			strcat( line, word );
			strcat( line, " " );
		}
		count++;		/* for the space separating words */
	}
	if( strlen( word ) > 0 )
		strcat( line, word ); /* print the last word if applicable */
	count = strlen( line ); /* remove trailing blanks */
	while( line[--count] == ' ' )
		line[count] = '\0';
	printf( "%s\n", line );
	exit( 0 );
}

int getword( word )
char	*word;		/* storage for word read */
{
	int	endflag = NO;		/* Does this word end a sentence? */
	int	beginflag = YES;   /* Is this the begining of a new word? */

	while(( c = getchar( )) != EOF ) {
		switch( c ) {
			case '.':
			case '!':	/* end of sentence characters */
			case '?':
				endflag = YES;
				*word++ = c;
				break;
			case ' ':
			case '\t':	/* word delimiters - white space */
			case '\n':
				if( beginflag == YES )
					continue; /* skip leading whitespace */
				*word = '\0';	  /* terminate word */
				return( endflag );	/* Non-EOF return */
			default:	/* just another character */
				endflag = NO;
				*word++ = c;
		}
		beginflag = NO;		/* no longer at beginning of word */
	}
	*word = '\0';		/* terminate the last word */
	return( EOF );
}
#ifdef bsd
/*
 * getopt - get option letter from argv
 */

#include <stdio.h>

char	*optarg;	/* Global argument pointer. */
int	optind = 0;	/* Global argv index. */

static char	*scan = NULL;	/* Private scan pointer. */

extern char	*index();

int
getopt(argc, argv, optstring)
int argc;
char *argv[];
char *optstring;
{
	register char c;
	register char *place;

	optarg = NULL;

	if (scan == NULL || *scan == '\0') {
		if (optind == 0)
			optind++;
	
		if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
			return(EOF);
		if (strcmp(argv[optind], "--")==0) {
			optind++;
			return(EOF);
		}
	
		scan = argv[optind]+1;
		optind++;
	}

	c = *scan++;
	place = index(optstring, c);

	if (place == NULL || c == ':') {
		fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
		return('?');
	}

	place++;
	if (*place == ':') {
		if (*scan != '\0') {
			optarg = scan;
			scan = NULL;
		} else if (optind < argc) {
			optarg = argv[optind];
			optind++;
		} else {
			fprintf(stderr, "%s: -%c argument missing\n", argv[0], c);
			return('?');
		}
	}

	return(c);
}
#endif
--------------------------------------------------------------------
Ed Reeder
Intel Corp.
Hillsboro, OR

akf@blia.BLI.COM (Andrew Fullford) (01/30/88)

In article <1723@ttidca.TTI.COM>, kevin@ttidca.TTI.COM (Kevin Carothers) writes:
> 
> NOW ---
> For all you 'nroff' gurus out there;
> 
>      I can't seem to get nroff to  keep from inserting all those lines of
>      blank stuff in my buffer. Any suggestions?

Preceding your text with the following nroff requests eliminates the
blank lines and more closely simulates 'fmt' by disabling hyphenation
and adjusted right margins:

	.pl 1
	.hy 0
	.na

If you have access, or the ear of your system supervisor, these can
be installed in /usr/lib/tmac/tmac.fmt (say).  Instead of mapping
a reformat key to

	{!}fmt^M

map it to

	{!}nroff -mfmt^M

This is a little slower than fmt (nroff is bigger), but if you don't
have fmt ...

With a little shell script work, you can also make a fmt this way,
and no need for access to /usr/lib/tmac.


Andrew Fullford
Britton Lee, Inc.

jamesp@dadla.TEK.COM (James T. Perkins;1149;92-725;LP=A;60eC) (02/05/88)

In article <1806@ttidca.TTI.COM> kevin@ttidcb.tti.com (Kevin Carothers) writes:

>>While it's true that vi gets a lot of bad (read "undeserved") press, I would
>>*not* consider this a shining example of its power.  In GNU Emacs, one moves
>>the point into the paragraph to be filled (assuming fill-mode is on), and
>>types ESC q to reformat the paragraph.  *No* blank lines are inserted.

>One thing that makes vi "powerful" on UNIX is that  it's  as
>closely  coupled  with  UNIX as "csh".  That is, whether one
>decides to format with "nroff", "fmt", or his/her  own  text
>pre-processor,  it's  totally  possible,  and just a command
>line away....

>Sure, a lot of text editors have a feature or two  for  mas-
>saging  a  paragraph or a margin. But  it's about useless if
>it's not *exactly* what you need/want. Why have a  bunch  of
>paragraph  formatters  around  when  mastery of one would be
>much more desireable?  The beauty of  vi  that I  stress  to
>people  who  don't  learn  it  (or don't think they have the
>patience to) is that you can  take advantage of  just  about
>everything UNIX has to offer *INSIDE* the editor.

I think what Kevin is trying to say is that vi is tied  into  the
UNIX shell closely enough and is powerful enough that you can use
any formatting program you want, instead of being limited to  one
packaged  with  and tied into the editor (like Wordstar paragraph
reformatting, to take an example--yech).

Its adamantly true that with most emacsi you could edit the ESC-q
paragraph  formatting function, or write a different one and bind
ESC-q to it instead of the default.

But you can do the same just as easily with vi.  What Kevin seems
to  be trying to say is that vi is every bit as powerful as emacs
in this way, in that you can map a key or sequence of  keys  (say
*p  to format a paragraph) to any imaginable formatting UNIX pro-
cess.

I myself have three vi paragraph formatters I use frequently, one
called  fmt  (a rewritten version of the Berekeley fmt program --
very like the rfm program posted here last week) that's  simplem-
inded  but  speedy and effective; cfmt which formats C-style com-
ments (I wrote it myself and it's a hack, but it's adequate); and
nfmt:

	:
	nroff | awk '
		{text[NR] = $0}
	NF>0	{last=NR}
	END	{for (i=1; i<=last; i++) print text[i]}' -

which runs nroff on the paragraph and then  strips  off  all  the
trailing blank lines (should be at least as powerful as the stan-
dard EMACS ESC-q).

Also, in my personal vi environment I can switch  between  nroff,
text, and c editing modes, with certain keystrokes and formatting
options set up for the appropriate editing mode.  Hence  in  text
mode,  the autowrap is set to maintain a two-character right mar-
gin, tabs are 8 characters wide and Q is mapped to !}fmt<CR>.  In
C mode, the autowrap is turned off, tabs are 4 characters wide, Q
is mapped to !}cfmt<CR>, and I have special maps to automatically
insert header comments; I could also enable commands to automati-
cally expand common C constructs; for example  typing  if'  while
inserting text, the editor would instantly expanded it to:

	if (_)
	{
	}

(the cursor is in insert mode at the "_").  I can switch  between
the modes simply by typing ",,".

And as far as I know most vi's will handle this degree of person-
alization.  BTW, this document was formatted with nfmt.

---

I'm not trying to tell emacs users to switch  to  vi.   I'm  just
telling vi users to explore vi and realize the beauty therein and
it's advantages and disadvantages.  Most vi users, even those us-
ing  vi  for 10 years, only use 50% of the capability of vi.  The
other 50% of vi allows at least a 2x productivity improvement.

Personally I have gotten used to thinking orthogonally when edit-
ing (example: hm.  Change next 3 paragraphs to "mary had a little
lamb", to beginning of line, yank first 3 words, 6 lines up,  put
before  the  cursor,  Indent two paragraphs by a tabstop, etc. --
translates to:

	c3}mary had a little lamb<ESC>
	^
	y3w
	6k
	P
	>2}

The most powerful feature of vi to me is the motion arguments  to
commands  (ex:  change *3* *paragraphs*, yank *3* *words*).  This
is like a simple english sentence with a  verb,  optional  count,
and  an  object.   Its  very mnemonic and for me it would be very
painful to have to remember a different pair  of  keystrokes  for
every little variation of yank, change, delete, etc.

 _	___
| |    / _ \   James T. Perkins, jamesp@dadla.la.tek.com, (503)629-1149
| |__ | |_| |  Tektronix Logic Analyzers, DAS System Software, Disk Services
|____||_| |_|  MS 92-725, PO Box 4600, Beaverton OR 97075

Killed processes never die... They just go to the big Bit Bicket in the sky.

robert@arizona.edu (Robert J. Drabek) (02/05/88)

There has been a problem I have had with formatting paragraphs in
vi: the definition using "}" seems to be "up to the next empty line",
but when editing *roff files I only want to format up to the next
line containing a dot command.

So, how do I easily tell vi to stop where desired?
-- 
Robert J. Drabek
Department of Computer Science
University of Arizona
Tucson, AZ  85721

jay@splut.UUCP (Jay Maynard) (02/06/88)

In article <2567@encore.UUCP>, pierson@encore.UUCP (Dan Pierson) writes:
> As an emacs hacker, I should probably stay out fo this but you might try:
> 	!'afmt
> which will produce no blank lines.  Or, if I misremember vi correctly,
> just move to the start of the paragraph and incant:
> 	!}fmt

There's only one little problem here;
fmt isn't a standard Unix command. It may be a standard BSD command, but it
wasn't on my System V.
If it's PD, is there a place I can snarf it? (I can even FTP, if I can
convince a friend...)

-- 
Jay Maynard, K5ZC (@WB5BBW)...>splut!< | GEnie: JAYMAYNARD  CI$: 71036,1603
uucp: {uunet!nuchat,academ!uhnix1,{ihnp4,bellcore,killer}!tness1}!splut!jay
Never ascribe to malice that which can adequately be explained by stupidity.
The opinions herein are shared by none of my cats, much less anyone else.

scott@tekcrl.TEK.COM (Scott Huddleston) (02/07/88)

A brief comment in the interest of accuracy.

Recent discussions on this topic have mentioned vi's filter-region capability
(!<motion><cmd>, e.g. "!}fmt" to reformat region .-to-EOparagraph) and
emacs's builtin justify-paragraph (usually bound to ESC-q).  The omitted
point is that (the more powerful) emacs's also have a filter-region command
which matches vi's generality in this case.

Both vi and emacs suffer from lack of standards -- emacs from multiple emacs
versions, and vi from lack of standards in the Unix (or non-Unix) environment 
it depends on (e.g., existence of "fmt" or other filters on a given system).

P.S.- If you don't have fmt (or misspell it), "!}fmt" can be unsettling when
it replaces your text with an error message.  But panic not, ":undo" repairs
the damage.

Disclaimer: this message is not intended to plug or pan either emacs or vi.

was@hplsdlw.HP.COM (William A. Stubblebine) (02/09/88)

/ hplsdlw:comp.editors / robert@arizona.edu (Robert J. Drabek) writes:

> There has been a problem I have had with formatting paragraphs in
> vi: the definition using "}" seems to be "up to the next empty line",
> but when editing *roff files I only want to format up to the next
> line containing a dot command.

> So, how do I easily tell vi to stop where desired?
> -- 
> Robert J. Drabek
> Department of Computer Science
> University of Arizona
> Tucson, AZ  85721
> ----------

In your .exrc file try:

set para=P\ DSDETSTEALDLBLRLLILESGspbp
set sect=H\ SKNHSHHU

Set para will cause } or { to stop at the following n/troff commands (in
addition to a blank line):

.P		  .TE		    .RL		      .SG
.DS		  .AL		    .LI		      .sp
.DE		  .DL		    .LE		      .bp
.TS		  .BL

(Note the treatment of the single letter macro .P - the space must be
escaped.)

Similarly, set sect will cause ]] or [[ to stop at the following n/troff
commands (in addition to start/end of file:

.H		  .NH		    .SH		      .HU
.SK

You may substitute other favorite n/troff commands, but there is a limit
to the number of paragraph definitions, which, for my vi implementation,
is defined by the length of the set para directive above.

                                Bill Stubblebine
                                Hewlett-Packard Logic Systems Div.
				8245 N. Union Blvd.
                                Colorado Springs, Co. 80918
				ARPA: was%hp-lsd@hplabs.hp.com
				UUCP: {hplabs,hpfcla}!{hpldola,hp-lsd}!was
                                (303) 590-5568