Centering lines in vi

Maarten Litmaath maart at cs.vu.nl
Tue Sep 12 09:40:46 AEST 1989


rostamia at umbc3.UMBC.EDU (Rouben Rostamian) writes:
\Does anyone know a combination of commands that will center a given line 
\(or better yet, a range of lines) in vi?  

I think you're better off filtering the range through some nroff shell script.
Example (to set indentation and linelength):
----------8<----------8<----------8<----------8<----------8<----------
#!/bin/sh

# usage: fill [indent] [linelength]
# author: Hans-Juergen Ehling (eh at astbe.uucp)

indent=${1-0}
llength=${2-72}

tmp=/tmp/format.$$
umask 077

/bin/rm -f $tmp
exec 3>&1 > $tmp 4< $tmp
/bin/rm -f $tmp

echo ".hy 0
.ll $llength
.in $indent"

tr -s ' ' ' ' # To squeeze blanks

nroff <&4 >&3
----------8<----------8<----------8<----------8<----------8<----------
Usage:
	!}fill 3 78

to reformat up to the end of the paragraph.

\A (perhaps) related question:
\Is there a command that returns the current column position of the cursor 
\in vi?

I guess not. :-(
Maybe some disgusting macro...
-- 
C, the programming language that's the same |Maarten Litmaath @ VU Amsterdam:
         in all reference frames.           |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list