billd@infmx.informix.com (William Daul) (05/24/91)
Can you...huh? Can you? How? Thanks, --Bi((
was@hp-lsd.COS.HP.COM (Bill Stubblebine) (05/25/91)
re: centering lines in vi:
This works for me on HPUX vi:
map v :s/^[ ^I]*//^M:s/[ ^I]*$//^M$ma81a ^V^[81^V|D`alxd0:s/ / /g^M$p^M
" <--------------------------><-><------><--->|<----><---------><-->
" | | | | | | | |
" delete leading and | | | | | | | |
" trailing white space ---+ | | | | | | |
" | | | | | | |
" mark the last non-white char ---+ | | | | | |
" | | | | | |
" add 81 spaces to the end of the line -+ | | | | |
" | | | | |
" go to column 81 ----------------------------+ | | | |
" | | | |
" delete from column 81 to end of line ----------+ | | |
" | | |
" delete all the non-white characters ---------------+ | |
" | |
" replace each pair of remaining spaces with a single space -+ |
" |
" replace the non-white chars at the end of the spaces --------------+
Notes:
1. Make the following substitutions in the map command above:
^I -> real tabs (cntl-I).
^M -> carriage return (cntl-M)
^V -> cntl-V
^[ -> escape (cntl-[)
2. After making the control character substitutions, you can insert the
whole paragraph, including comments (with the leading '"') into your
.exrc file so you can remember what this kluge does two months from now.
(You'll have to adjust the field delimiters in the first line of the
comment after replacing the ^I's with real tabs.)
3. I know there are ways to do this with !! shell escapes, but centering
usually involves only a few lines at most, and on most vi's a macro is
much faster than firing up a shell escape.
4. The main drawback is that the length of the region within which the text
is centered (usually the screen width) is hard-wired to 80 in this
example. Since I usually work with 80 column screens even on X windows,
this has not proven to be a severe limitation. To change the width of
the centering field from 80 to N, change each instance of 81 to N+1.
If there is a clever way to write this macro to automatically adjust to
varying screen widths (other than editing the .exrc file), I'd like to
hear about it.
Bill Stubblebine
Hewlett-Packard Logic Systems Div.
8245 N. Union Blvd.
Colorado Springs, CO 80920
was@hp-lsd.col.hp.com (Internet)
(719) 590-5568