[comp.unix.misc] VI

billd@infmx.informix.com (William Daul) (03/06/91)

Is there a way to fully justify text in VI?

Is there a VI Internet group?  I am sure there
are a ton of tricks/shortcuts that we all know
but each one of us doesn't.

Thanks,  --Bi((

karish@mindcraft.com (Chuck Karish) (03/07/91)

In article <1991Mar5.223022.14261@informix.com> billd@infmx.informix.com
(William Daul) writes:
>Is there a way to fully justify text in VI?

    :map @ 1Gi.ad b^V^M^V^[-!Gnroff

(all keystrokes shown; "^V" (CTRL-V) is there to escape the
carriage return and the ESC)

After you make this macro, typing '@' from command mode will call
nroff to justify the whole file.

	Chuck Karish		karish@mindcraft.com
	Mindcraft, Inc.		(415) 323-9000

tchrist@convex.COM (Tom Christiansen) (03/07/91)

From the keyboard of karish@mindcraft.com (Chuck Karish):
:    :map @ 1Gi.ad b^V^M^V^[-!Gnroff

I would not suggest rebinding @ -- it's a very useful command.
It would horribly break my exrc, amongst many others I'm sure.
I routinely put things in buffer to execute them.

--tom
--
	I get so tired of utilities with arbitrary, undocumented,
	compiled-in limits.  Don't you?

Tom Christiansen		tchrist@convex.com	convex!tchrist

kimcm@diku.dk (Kim Christian Madsen) (03/07/91)

billd@infmx.informix.com (William Daul) writes:

>Is there a way to fully justify text in VI?

You cannot in any way justify text, unless you know the pre-
cise  meaning of the text, not in vi nor in any other editor
word-processor (-;

Actually it is possible to have text fully adjusted  in  vi,
however  it  requires  an external program, such as nroff or
the like. What you do is to pipe the text from vi  into  the
external program and replacing the original content with the
adjusted content. The command for doing this to a  paragraph
is  "!}<command>" and from the cursor position to the end of
document "!G<command>" as in "!Gnroff -me".

				Regards,
				Kim Chr. Madsen
				kimcm@diku.dk

PS. This text was written in vi and adjusted with nroff.

javey@hybrid.UUCP (shahram javey) (03/11/91)

Someone had asked how do you justify the text from within vi:

>From the keyboard of karish@mindcraft.com (Chuck Karish):
>:    :map @ 1Gi.ad b^V^M^V^[-!Gnroff
>

If simple text formatting is sufficient for your needs try

:%!fmt

The above format the whole file. If you just want to format lines 
10 to 30, say, try

:10,30!fmt

cheers...sj

dattier@vpnet.chi.il.us (David W. Tamkin) (03/12/91)

javey@hybrid.UUCP (shahram javey) wrote in <1991Mar10.215552.8366@hybrid.UUCP>:

| Someone had asked how do you justify the text from within vi:

| If simple text formatting is sufficient for your needs try
| :%!fmt

fmt must be something in BSD Unix.  The question of justifying within vi
comes up often, and someone always says "Filter through fmt, that's all!"

Then someone else says, "There's no fmt on my system."  I've certainly never
found it anywhere I've had shell access.

(Actually, fmt, if it does what I think it does, will just reduce the
raggedness of the right edge; it won't right-justify text.  My personal
opinion is that ragged-right text is far easier to read, but that's another
matter.  Perhaps there are some command-line options to fmt that will make it
actually justify the right margin or, if that's what it does with no options
specified, there might be an option to have it produce output with a ragged
right margin as great as possible without exceeding a specified maximum.)

David Tamkin  PO Box 7002  Des Plaines IL  60018-7002  dattier@vpnet.chi.il.us
GEnie:D.W.TAMKIN  CIS:73720,1570  MCIMail:426-1818  708 518 6769  312 693 0591

merlyn@iwarp.intel.com (Randal L. Schwartz) (03/14/91)

In article <1991Mar12.055337.10655@vpnet.chi.il.us>, dattier@vpnet (David W. Tamkin) writes:
| fmt must be something in BSD Unix.  The question of justifying within vi
| comes up often, and someone always says "Filter through fmt, that's all!"
| 
| Then someone else says, "There's no fmt on my system."  I've certainly never
| found it anywhere I've had shell access.
| 
| (Actually, fmt, if it does what I think it does, will just reduce the
| raggedness of the right edge; it won't right-justify text.  My personal
| opinion is that ragged-right text is far easier to read, but that's another
| matter.  Perhaps there are some command-line options to fmt that will make it
| actually justify the right margin or, if that's what it does with no options
| specified, there might be an option to have it produce output with a ragged
| right margin as great as possible without exceeding a specified maximum.)

If the text is simple (relatively troff-escape free), I just put

	.ad b
	.ll 70
	.pl 1

in front, and say

	!!nroff

Simple.

Just another 'roff hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/

tchrist@convex.COM (Tom Christiansen) (03/14/91)

From the keyboard of merlyn@iwarp.intel.com (Randal L. Schwartz):
:If the text is simple (relatively troff-escape free), I just put
:
:	.ad b
:	.ll 70
:	.pl 1
:
:in front, and say
:
:	!!nroff
:
:Simple.

Well, yes, but you need more than a one-line region (!!) to pipe through.

--tom

mjr@hussar.dco.dec.com (Marcus J. Ranum) (03/14/91)

merlyn@iwarp.intel.com (Randal L. Schwartz) writes:

>If the text is simple (relatively troff-escape free), I just put
>
>	.ad b
>	.ll 70
>	.pl 1
>
>in front, and say
>
>	!!nroff

	You can actually just make that into a vi macro. :) Hmmm..

map N i.ad b^M.ll 70^M.pl 1^[!!nroff^M

	or something like that.

mjr.

curt@cynic.wimsey.bc.ca (Curt J. Sampson) (03/15/91)

In article <1991Mar12.055337.10655@vpnet.chi.il.us> dattier@vpnet.chi.il.us (David W. Tamkin) writes:
>javey@hybrid.UUCP (shahram javey) wrote in <1991Mar10.215552.8366@hybrid.UUCP>:
>
>| Someone had asked how do you justify the text from within vi:
>
>| If simple text formatting is sufficient for your needs try
>| :%!fmt
>
>fmt must be something in BSD Unix.  The question of justifying within vi
>comes up often, and someone always says "Filter through fmt, that's all!"

Yes, it is a BSDism.  However, it is available to the public at
large.  A copy comes with the mailx package.  You can ftp it from,
among other places, wimsey.bc.ca (~ftp/pub/mail/mailx.tar.Z).

cjs
-- 
			| "It is actually a feature of UUCP that the map of
curt@cynic.uucp		| all systems in the network is not known anywhere."
curt@cynic.wimsey.bc.ca	|	--Berkeley Mail Reference Manual (Kurt Schoens)

dmckeon@hydra.unm.edu (Denis McKeon) (03/21/91)

For quick & dirty justification within vi, try:

:map + J074lBhr^V^M

where ^V^M is control-V control-M, of course.  It does a join, then a
split before the word that bridges col 74 (season to taste).  This
allows you to handle the small case of a few lines, or a short paragraph
by repeatedly hitting + down to the last line (and without !'ing out).

Bugs
	it assumes that the first two lines together are >= 74 chars.

	you'll have to open a fresh empty line after the paragraph.

	you'll need an empty line after the last line in the document

	TAB characters are counted as 1 char instead of <tabstop> chars.

	there was ome reason to use 074l instead of 74|, but I don't
	recall what the reason was.

Overall, this is a messy hack - but when you use vi on a PC, without 
any normal Unix utilities, let alone fmt, it is a (very) small blessing.

--
Denis
dmckeon@hydra.unm.edu

Dan_Jacobson@ATT.COM (03/22/91)

I don't want to be mean, but in GNU Emacs
describe-key ESC q
fill-paragraph:
Fill paragraph at or after point.
Prefix arg means justify as well.

in <a future article> my_conscience@my_brain said:
>Yeah, well he wanted to do it on a PC, and GNU Emacs I don't think
>runs on a PC!

OK, OK.
-- 
Dan_Jacobson@ATT.COM  Naperville IL USA  +1 708 979 6364