[alt.religion.computers] vi for power users

tchrist@convex.COM (Tom Christiansen) (12/06/90)

In article <joshi.660440350@m.cs.uiuc.edu> joshi@cs.uiuc.edu 
(Anil Joshi) writes:

>The problem I find with these editors is that the manuals are hard to
>get. One has to read the research papers that were written by the
>original authors etc. Why can't there be a reasonable and comprehensive
>manual with lots of examples? 

There are books on vi available.  Go to a good technical bookstore.

>Talking about ex, one can use abbreviations to do a lot of good stuff but the
>ex macros (I am calling the abbreviations macros) are also key stroke
>dependent (like having to hit ctrl-v before inserting other control
>chars. into the macro.). Is there some way of getting parameters to the
>macros?

Not exactly, but I think I can probably do anything you would like
done.  Post your problem, I'll post an answer.

>Another problem which I have not solved yet is that while I am editing a
>file and want to change my function keys, can I run some other .exrc
>like file from inside the editor? 

Sure, just use the ":so otherexrc" command.

I haven't posted this for a while, so here's my .exrc; it's something
to stick in the faces of emacsoids, who think vi is not an extensible
editor.  Just remember: EMACS belongs in <sys/errno.h> :-)

Now, it's true that it doesn't start up particularly quickly on 
diskless Suns, but what does?  It works just fine on my Convex. :-)

I've commented out a few things that won't work in all versions.  There
are pretty extensive comments, but you'll want to try them out to really
appreciate the stuff.  A couple of these are just for fun, but most are
quite helpful.  Some are really, really helpful.

I've run this all through "cat -v" so that it gets there semi-
intact, so you'll have to undo this.  A problem is that there are 
some real carets in here.  They are on these maps: 
    \C \l ^X ^Y \r
It should be obvious which are real.    If you run the file 
through this filter:
    perl -pe 's/\^(.)/sprintf("%c",ord($1) &~ 0x40)/ge'
It will uncat-v the whole thing, and then you should go fix up the 
five maps listed above.  If you don't have perl (shame on you! :-)
then you'll have do it by hand; that substitute doesn't work quite
as well in sed. :-)

--tom

"	tom christiansen's .exrc file <tchrist@convex.com>
"
"
set terse
"	because we prefer terse error messages,
set writeany autowrite
"	because we want to write out our file whenever we can,
"	like on a :tag, :stop, or :next
set tabstop=8 
"	so tabs look right for us 
set shiftwidth=4
"	so ^T and << are smaller 
set report=1
"	so we our told whenever we affect more than 1 line 
set nomesg
"	because being talked to during an edit is aggravating
set autoindent
"	so i don't have to tab in 
set redraw optimize
"	keep the screen tidy
"
"
"	INPUT MACROS that i always want active
"
map! ^Z ^[:stop^M
"	so i can stop in input mode.  note that autowrite is set, so 
map! ^A ^[:stop!^M
"	will stop me without writing.
"
map! ^K ^V^[O
"	lets me do kindof a negative carriage return in input mode.
"map! ^B ^[bi
"	non-destructive ^W
"map! ^F ^[Ea
"	and its inverse
"
"
"	ARROW MACROS next four let arrows keys work in insert mode; 
"
map! ^V^[OA ^V^[ka
map! ^V^[OB ^V^[ja
map! ^V^[OC ^V^[lli
map! ^V^[OD ^V^[i
"
"
" 	Who says you can't emulate emacs in vi? :-)
"
map! ^B ^V^[i
map! ^F ^V^[lli
map! ^A ^V^[I
map! ^E ^V^[A
"
"
"	EXCHANGE MACROS -- for exchanging things
"
map v xp
"	exchange current char with next one in edit mode
map V :m+1^M
"	exchange current line with next one in edit mode
map! ^P ^V^[hxpa
"	exchange last typed char with penultimate one in insert mode
map = ^^
"	edit previously editted file
"
"
"
"	other macros
"
map g G
"	because it's easier to type
map ^A :stop!^M
"	unconditional stop
map ' `
"	so we return to exact position, not just ^ on 'a or ''
map Y y$
"	so Y is analagous to C and D
map ^R ddu
"	single-line redraw
map ^N :n +/^M
"	go to next file in arg list, same position 
"	useful for "vi +/string file1 file2 file3"
"
"
"	META MACROS, all begin with meta-key '\' ; more later in file
"
map ^V	 \
"	so can use both ^I and \ for meta-key
"
map * i^M^[
"	split line
"
map \/ dePo/\<^V^[pA\>^V^["wdd@w
"	find current word, uses w buffer
"
map \w :w^M
"	write out the file
"
map \C o^V^[k:co.^V^M:s/./ /g^V^Mo^V^[80a ^V^[:-1s;^;:s/;^V^M:s;$;//;^V^M"mdd@m:s/\(.\)./\1/g^V^M:s;^;:-1s/^/;^V^M"mdd@mjdd
"	center text
"
"	EXECUTION MACROS --	these two are for executing existing lines.  
"
map \@ ^V^["mdd@m
"	xqt line as a straight vi command (buffer m, use @@ to repeat)
map \! 0i:r!^V^["ndd@n
"	xqt line as :r! command (buffer n, use @@ to repeat)
"
map \t :r!cat /dev/tty^M
"	read in stuff from X put buffer
"	
"	c-hacking exrc source, useful on c programs et al, but not text
"
set modelines
"	so that we spot lines like /* vi:set tabstops=3 */
"	at the top of a file, kinda like file-specific exrc commands
"
set tags=tags\ /mnt/tchrist/tmptags\ /usr/lib/tags
"	tmptags is so can make tmp tag file of r/o src dirs
"	by "set d = $cwd;cd;ctags -twd $d/*.[ch];mv tags tmptags;cd $d'
"
"
"	BLOCK MACROS -- these make { and } hot keys in insert mode
"
map! ^O ^V^V^V{^M^V^V^V} ^V^[O^T
"	this will begin a block, leaving in insert mode
map! ^] ^V^[/^V^V^V}^V^Ma
"	and this  will take you past its end, leaving in insert mode
"
"
"
"	LINT MACRO.  deletes all text from "lint output:" and below, (if any)
"	replacing it with lint output in pretty block comment form.  could
"	do sed work myself, but this is faster.  
"
"	the map! is for subsequent map, not by people, 
"	tho /^Lo would make sense.
"	this is one of those famous time/space tradeoffs 
map! ^Lo lint output
"
"	and now for the real work
map \l Go^M/* ^Lo^M^[/^Lo^MdG:w^Mo/*** ^Lo^[<<:r!lint -u -lc %^V|sed 's/^/ *  /'^MGo***/^[N
"
"	indent this for me
"
map \i :%!indent -i4^M
"
"	COMMENTING MACROS -- these are actually pretty amazing
"
"	from edit mode, this comments a line
map ^X ^i/* ^[A */^[^
"
"	and this undoes it
map ^Y :s/\/\* \([^*]*\) \*\//\1^[
"
"	this next one defeats vi's tail-recursion defeatism
"	called by 2 maps following this one 
map! ^N ^V^[:unmap! ^V^V^M^[
"
"	while in insert mode, this will put you "inside" a comment
map! ^X ^V^[:map! ^V^V^M ^V^V^[a^V^V^V^No^[a /*  */^[hhi
"
"	while in edit mode, this begins a block comment -- ^N to escape
map \c	O/*^M *  ^M*/^[k:map! ^V^V^M ^V^V^M*  ^MA
"
"	and this is for adding more lines to a block comment -- ^N to escape
map \o	:map! ^V^V^M ^V^V^M*  ^MA
"
"
"	this stuff (probably) only works with UW vi.
"
set tagstack
"	so we can :tag and :pop deeper than 1 level
set filestack
"	so we can tag lookup on files and pop off
set path=/mnt/tchrist
"	so we can say "vi foo" or ":n foo" and look all those places
"	if the file is relative and not in .
set ?S1200:window=8
"	if (speed==1200) set window=8
"	cause the default is too much.
set ?Tcitc:fastfg
"	if (term==citc) set fastfg
"	
"	c-hacking exrc source that only works with UW vi
"
"set tagprefix
"	allows abbreviated tags.  better than std taglength
"
set exinit
"
" 	things i want active when editing text not programs
"	
set ignorecase
"	cause this is test
set wrapmargin=5
"	this sets autowrap 5 from right margin
"
"
map _ i_^V^V^V^H^V^[ll
"	this character will now be underlined when less'd
"
map \s :w^Mgo^V^[:$r!spell %^M
"	spell the file, placing errors at bottom, use \w to find
map \n Gdd\/
"	for find next spelling error
"
"
"	FORMATING MACROS
"
map \P .,$fmt -75^M
"	format thru end of document
map \p !}fmt -75^M
"	format paragraph
map \f 1G/---^Mj:.,$!fmt -75^M
"	format message
map \e :%!expand -4^M
"	expand tabs to 4 stops
"
map \r 1G/^-/^[:r!sed -e '1,/^$/d' -e 's/^./> &/' @ ^[/^-/^[j
"	read in @, quoted (for MH replies, who link @ to current file)
"
"
ab rrt Return-Receipt-To: tchrist
ab CCC CONVEX Computer Corporation
ab ccc convex computer corporation
ab Chr Christiansen
ab Dec December
ab dec december
ab Feb February
ab feb february
ab Fri Friday
ab fri friday
ab Int International
ab info information
ab Jan January
ab jan january 
ab Mon Monday
ab mon monday
ab nite night
ab Nov November
ab nov november
ab Oct October
ab oct october
ab Sat Saturday
ab Sep September
ab sep september
ab tho though
ab thru through
ab Thu Thursday
ab thu thursday
ab thur thursday
ab tonite tonight
ab Tue Tuesday
ab tue tuesday
ab univ university
ab Wed Wednesday
ab wed wednesday
ab WI Wisconsin
ab WI Wisconsin
ab Wi Wisconsin
ab wi wisconsin
ab wi wisconsin
ab Xmas Christmas
ab xmas christmas
"  my figners have dyslexia
ab covnex convex 
ab Covnex Convex 
ab versino version
"	
"set tagstack
"	so we can :tag and :pop deeper than 1 level
"set filestack
"	so we can tag lookup on files and pop off
"set path=/tac/tchrist\ /etc\ /usr/include\ /usr/include/sys
"	so we can say "vi foo" or ":n foo" and look all those places
"	if the file is relative and not in .
"set ?S1200:window=6
"	if (speed==1200) set window=8
"	cause the default is too much.
"set ?Tcitc:fastfg
"	if (term==citc) set fastfg
"	
"	stuff for text editing that will only work with UW vi
"
"	set up wrapmargin as 75 columns, thus letting me be quoted
"	this is so dumb.  wrapmargin should be absolute not relative
"
"set ?W80:wrapmargin=5
"set ?W132:wrapmargin=47
"set ?W98:wrapmargin=23
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
 to look at yourself in the mirror the next morning."  -me