The Advanced .exrc file

This file has been reformatted in HTML. To get a copy you can use as an .exrc file, get the uuencoded file. The use of custom filter programs and other options have been removed to make this file as generic as possible.

"==============================================================================
" The ADVANCED .exrc file
" Using this file is a lot easier than understanding it. If you are an old
" hand at vi(1) you'll find this a good read. If not, I'd recommend you use
" the BEGINNER .exrc file.
"==============================================================================
" John S. Urban; last updated 02/10/91
" tested on UNICOS,Sun SPARC,CDC910,RISC 6000,APOLLO DN1000,DECstation 5000
" RISC 6000, NeXT, ... DECstation 5000 didn't allow :set showmode.
"==============================================================================
" vi(1) rewards study. Although vi(1) use is not intuitive,  it
" is  a  flexible editor that can be used from virtually any keyboard. The
" regular expressions it uses are also useful when using  other  utilities
" such  as  sed  and  awk.  It  is  a particularly nice editor for touch-
" typists, as fingers rarely if ever have to leave the "home" position.
"
" This  .exrc prologue file for the vi editor makes  many  edit  functions
" easier  by  using  often-overlooked  features  of  vi  such as the  :map
" command  and filtering  thru  shell  commands  (and  comments  in  .exrc
" files).
"
" The major commands added or made easier to access all are two character
" sequences starting with a comma. Almost all commands act on the marked
" region from mark a to mark b. For example, go to the TOP line of a
" region of text and enter ",a" then go to the BOTTOM line of the region
" and enter ",b". Now to MOVE that region to another part of the file
" place the cursor there and enter ",m". You don't have to count lines or have line
" numbers on to move, copy, delete, filter or collect up ranges of lines!
"
" The most commonly used "comma" functions are  a(bove) b(elow) c(opy)
" d(elete) m(ove) M(arked) o(utput)
"
" To print other goodies in this file use
"   cat -v -e -t|lpr
" Then study the comments. If you don't use this special version of cat you
" might find this file difficult to print because it contains control characters.
"
" ,e ,t ,T are good ones to start with next. ^Wword^W is a good one too.
" NOTE:
" If you vi(1) this file note that ^ in this file sometimes designates using
" the control key with the following letter; sometimes it just means "^".
" To tell the difference, try and place the cursor on the ^. If it won't
" stay on the ^ but jumps over it the "letter" to the right of the ^ 
" is not a letter, but a special character generated by typing that letter
" while depressing the control key.
"
" CAUTION: This .exrc file  uses  and  changes  marks  and  buffers  named
" "abcdefghij" quite freely and assumes the user in general does not.  The
" major functions defined herein "communicate" using marks. you'll  almost
" never  use  anything  except  ,a  and ,b to mark the top and bottom of a
" region and ,F to mark the entire file.
"
" If you are adding macros of  your own use other marker  names  (n-z)  or
" use  the  marks  consistent with their current use.  Mnemonically (well,
" sort of) the marks are mark a(above),  b(below),  c(current),  d(current
" page home) e(current page middle) f(current page bottom)
"==============================================================================
" HOW THE COMMA COMMANDS WORK:
"
" Many people would be surprised to discover that vi(1) and curses(3c) and
" terminfo(5) support keyboard function keys. It's just that most terminfo
" files don't bother to DEFINE the function keys and that you can get to all
" the functionality  of vi(1) without function keys (which vary from keyboard
" to keyboard, making it difficult to know where particular functions are
" anyway -- no big loss).
"
" In vi if your terminfo(5) file does NOT define the corresponding function
" key you can execute that function by entering #LETTER where LETTER is the
" letter designation for a particular key. You can see the strings assigned
" to particular function key names by entering ":map".
"
" VERY few terminfo files define the function keys except functions 1,2,3 and 4.
" And if anyone ever did it's pretty easy to make a copy that does NOT (see
" tic, untic, infocmp  and terminfo or termlib if you really want to know about
" some relatively arcane stuff. When there were hundreds of terminal types out
" there this was important but it is almost never altered anymore).
"
" Unfortunately, the #[.] method
" of executing a function key string only works WHEN THE KEY DOES NOT
" EXIST. if you do a ":map #1 1g" for example, #1 will not usually execute the
" string but pressing function key 1 (often PF1 on a vt100) will. Why
" the #[.] doesn't ALWAYS work is beyond me. But we will use the function
" names a-z and A-Z which I have only seen defined once.
"
" So to execute the "undefined" function keys, you enter #[.]
" where [.] is the letter used after the # character in the function-key
" mapping command. If "#" is your backspace or rubout character or
" is awkward to type on your keyboard, map another key to be equivalent
" to the "#" character. I suggest a comma. It is usually easy to type
" and the "real" vi function it performs isn't all that important so ...
map , #
" Now to execute "function key a" you can enter ",a" (or still use "#a").
"==============================================================================
" CAUTIONS regarding construction of a .exrc file
"
" put this .exrc file in your $HOME directory.
"
" Blank lines are NOT permitted in .exrc files.
"
" The environmental varible EXINIT should be unset or include the command
"    source ~/.exrc
"
" SOME versions of vi(1) slow down incredibly at start-up if there are comments
" in the .exrc file, so you might want to maintain two copies of .exrc. Put
" the master in .exrc.COMMENTED and the working copy in .exrc
"    grep -v '^ *"' <.exrc.COMMENTED >.exrc
"
" Consider carefully where you want vi(1) to write it's working scratch files.
" Make sure their is lots of room so you do not run out of scratch space.
" set directory=/tmp
"
" Note that this file contains tab characters and significant blanks at ends
" of lines. Use :
"   set list
" to see them while editing.
"==============================================================================
" first, here are some modes to make vi behave a bit more friendly:
set autoindent ignorecase | map g 1G
" Most of the time you will like having autoindent on. It makes the next line
" of text start with the same margin as the line above it. But if you don't
" know to enter ctrl-D as the first thing on the line to override the indent
" for the current line you won't like this mode neary as much!
"
" set notimeout
" notimeout is required using xterm from workstation to UNICOS or rapid
" cursor movement with cursor keys does not work properly, as some
" escape characters don't make it in time.
" note that it does not seem to happen with DEC dxterm using 7-bit controls
"
" SGI IRIX does not permit notimeout as a toggle but requires a value
"
" If you ever do want your searches to be case sensitive, use TAB i.
"===============================================================================
" Most keyboards have : on a shifted key and ; on the same key unshifted.
" On my keyboard, a colon (used often) is harder to hit than a semicolon
" but I need to use the colon command a lot so lets make a semi-colon
" equivalent to a colon:
map ; :
" NOTE:
" Personally, I almost never have use for the "fFtT;," commands. I've already
" changed the function of ; and , in this file from their defaults.
"===============================================================================
" speaking of abbreviations, I do have a few I use. The ab command makes
" the substitution in input mode. This is not only when you are entering
" text but when you are using an ex : command.
ab JSU  John S. Urban
" help me out with my chronic misspellings:
ab similiar similar
ab hhDL <DL><DD>ItemName<DT>DescriptiveText<DD>ItemName<DT>DescriptiveText</DL>
"===============================================================================
" NOW LETS DEFINE MOST EVERYTHING SORT OF ALPHABETICALLY:
"===============================================================================
"a Set ABOVE marks A and B so range for move, copy and delete is current line
map #a mamb
"==============================================================================
" b Set BELOW mark B
map #b mb
"------------------------------------------------------------------------------
" B  delete multiple BLANK lines below to next non-blank line
"    o If current line is non-blank, gap between this paragraph and
"      next is closed (all blank lines are removed).
"    o If current line is blank all blank lines BELOW the current
"      line are deleted until a non-blank line is encountered.
"          o Because a non-blank line must be encountered another
"            command must be used to delete trailing blank lines at end of
"            file (e.g. dG or :.,$d)
"          o If wrapscan is set and use on last blank line in file
"            lines from first blank region in file will be removed
"          o If on LAST blank line before a non-blank region NEXT blank
"            region will be removed.
map #B :/^[ ^I]*$/;/[^ ^I]/-1d^M
"===============================================================================
" c COPY mark ab to current position. USES CURRENT REGION, NOT BUFFERED.
"   (left at end of inserted text, use #V to view line on before operation)
map #c K:'a;'bco'c^M
"------------------------------------------------------------------------------
" C SEE CURRENT lines where marks ab are (versus #s which shows entire region).
map #C K:'a=^V|'b=^V|'ap^V|'bp^M'e`C
"==============================================================================
" d DELETE mark ab (returned to original viewing position)
"   If c or d is in ab will get error bell. DELETED TEXT APPENDS TO BUFFER d.
map #d K'a"Dd'b'e`c
"------------------------------------------------------------------------------
" D DELETE mark ab (returned to original viewing position)
"   If c or d is in ab will get error bell. DELETED TEXT REPLACES BUFFER d.
map #D K'a"dd'b'e`c
"==============================================================================
" e EXECUTE command using marked region as input and replace region with output
"   filter text thru commands like tr,pr,cb,asa,nasa,fold and such.
map #e K'a!'b
"==============================================================================
" f Paragraph FILL marked region using fmt(1) fill program
map #f K'a!'bfmt^M
" there are fancier filters such as adjust(1) on some systems
"------------------------------------------------------------------------------
" F change marked region to entire FILE
"map #F K1GmaGmb'e`c
map #F K:1ma a^V|$ma b^M'e`c
"==============================================================================
" g   go to top of file
map g 1G
"------------------------------------------------------------------------------
" I use several keyboards where <esc> is hard to reach, and ^G is nothing
" but an abbreviation for :f<cr>, so lets map the bell character to be an escape
" so my escape is always somewhere easy to reach
map  ^[ |map!  ^[
"==============================================================================
" H HELP (display ALL comment lines in .exrc)
map #H :!grep '^"' $HOME/.exrc^V|more^M
"==============================================================================
" i indent mark by 3 characters.
map #i K:'a,'bs/.*/   &/^M
"------------------------------------------------------------------------------
" I use cb command to indent a C source code and remove tabs (cb not on all systems)
map #I 1G!Gcb^V|expand -3^M
"==============================================================================
" Macro space is limited. Don't repeat sequences in different macros.
" In many of the macros it is convenient to mark the current, home, and
" middle positions so you can return to that view, so define K to mark
" those locations
map K mcHmdMme
"==============================================================================
" l convert MARK ab to LOWERCASE.
map #l K:'a,'bs/.*/\L&/^M
"==============================================================================
" m MOVE mark ab to current position
"   (left at end of inserted text, use #V to view line on before operation)
map #m K:'a;'bm'c^M
"------------------------------------------------------------------------------
" M abbreviation for starting an ex command with the range set to 'a'b.
map #M K:'a;'b
"==============================================================================
" n like n (locate next) except puts located line at top of screen
map #n nz^M
"------------------------------------------------------------------------------
" N like N (locate previous) except puts located line at top of screen
map #N Nz^M
"------------------------------------------------------------------------------
" go to next file in list if started vi with multiple filenames and show
map  :n^V|args^M
"==============================================================================
" o OUTPUT the buffer stored with functions d,D,y and Y
" O OOPS! put last 9 unnamed deletes or yanks at current position
"   WARNING: USING THIS COMMAND SEEMS TO HOSE UP ALL BUFFERS a-z
map #o "dp
"------------------------------------------------------------------------------
" This map command causes letter buffers and number buffers to be erased
" unless all these buffers exist!! BUG
" map #O "1p"2p"3p"4p"5p"6p"7p"8p"9p
map #O "1p........
"==============================================================================
" p PARAGRAPH fill current paragraph using vi-fill program
map #p {!}fmt^M
"------------------------------------------------------------------------------
" P change marked region to current paragraph
map #P K{ma}mb'e`c
"------------------------------------------------------------------------------
" rewind argument list of files (see )
map  :rew^V|args^M
"==============================================================================
" r REMEMBER the current file position for return with capital R (bookmark)
map #r miMmj`i
"------------------------------------------------------------------------------
" R RETURN to the spot remembered with lowercase R (go to bookmark)
"   The REMEMBER/RETURN will not work if the remembered "screen" home and/or
"   current line have been deleted.
map #R 'jz.`i
"------------------------------------------------------------------------------
" read the output of a shell command (e.g. date,cal,grep STRING FILE, ...)
map  :r!
"==============================================================================
" s SHOW marked region
map #s K:'a;'bnu^V|'c;'d^M
" map #s K:'a=^V|'b=^V|'a;'bp^V|'c;'d^M
"------------------------------------------------------------------------------
" S change marked region to current screen.
map #S KHmaLmb`c
"==============================================================================
" t TRIM TRAILING white space (spaces and tabs) from marked region.
map #t K:'a,'bs/[ ^I][ ^I]*$//g^M
"------------------------------------------------------------------------------
" T Use expand(1) program to expand TABS out
map #T K'a!'bexpand^M
"==============================================================================
" u convert MARK ab to UPPERCASE.
map #u K:'a,'bs/.*/\U&/^M
"==============================================================================
" v read in current X11 window buffer using pb0 script, xprop(1) and c-code
map v :r!pb0^M
"------------------------------------------------------------------------------
" Change case of word:
"    yank W to change case of
"    set mark n to where you are
"    output the yanked text
"    turn it all to ~ characters
"    put it into named buffer n
"    delete the line
"    go to mark n
"    execute buffer n ( The line of ~s)
map V yWmno^[P:s/./\~/g^M0"nDdd`n@n
"------------------------------------------------------------------------------
" v Return to VIEW of original current line before #C or #M or most # commands.
" The standard command '' will do the same most of the time.
map #v 'dz^M`c
"==============================================================================
" w write marked region to a file you specify
map #w :'a;'bwSPACE
"------------------------------------------------------------------------------
" locate all word in marked region: ^w string ^w
" (To do the whole file use ,F first)
" To step do a ,a and try to find it on current line, then use n and N to
" find next and previous
map   K:'a;'bg/\<
map!  \>/#^M
"==============================================================================
" X DELETE (X-OUT) marked words (cannot put in mapped macros!!!! use p to move)
map #X mc`ad`b`c
"------------------------------------------------------------------------------
"From: William J Seng <oswms> Date: Mon, 11 Nov 91 17:39:10 -0500
" ^X  put brackets around the current word
map  i(^[Ea)^[
"==============================================================================
" y YANK mark ab (returned to original viewing position)
"   YANK TEXT APPENDS TO BUFFER d.
map #y K'a"Dy'b'e`c
"------------------------------------------------------------------------------
" Y YANK mark ab (returned to original viewing position)
"   YANKED TEXT REPLACES BUFFER d.
map #Y K'a"dy'b'e`c
"==============================================================================
"  forced write of file; then go to next file
map  :w!^V|n^M
"==============================================================================
" Somewhat dangerous: escape sequences to set a vt100 to 132 and 80 column mode
" If your terminfo/termcap definition and communication path support the
" WindowChange signal, and if your terminal obeys 132 column switching (An
" xterm can, but you have to turn that option on), this can be very handy.
" If may not work. I know why, I just DON'T want to explain it to anyone.
map #1 :!echo '^V^V^[[?3l'^M^M
map #2 :!echo '^V^V^[[?3h'^M^M
"==============================================================================
" some vt100 emulators do not allow cursor keys to send application mode
" strings, so make vt100 normal mode arrow keys do cursor positioning too.
map ^[[A k
map ^[[B j
map ^[[C l
map ^[[D h
" if in input mode, cursor keys take you out of input mode (vt100 strings)
" notes: if in :set showmode mode prompt is not removed from the screen
"        and don't necessarily go to proper column position. BUGS ?!
map! ^[[A ^[k
map! ^[[B ^[j
map! ^[[C ^[l
map! ^[[D ^[h
map! ^[OA ^[k
map! ^[OB ^[j
map! ^[OC ^[l
map! ^[OD ^[h
" This really should be fixed in the terminal definition file but this helps
" a lot of people use cursor arrows that want to.
"==============================================================================
"==============================================================================
" Tab commands:
" make tab key get to "second set" of functions (primarily filters and toggles)
map ^V^I #Z
"==============================================================================
" walker@hpl-opus.hpl.hp.com (Rick Walker)
"TAB n  toggles between numbered editing and non-numbered
map @NU@ :set nu^M:map #Zn @NONU@^M:"--- line numbering on --- "^M
map @NONU@ :set nonu^M:map #Zn @NU@^M:"--- line numbering off ---"^M
map #Zn @NU@
"==============================================================================
" walker@hpl-opus.hpl.hp.com (Rick Walker)
"TAB a  toggles between autoindent and noautoindent
"       turn off autoindent before using a "PASTE" in X11 windows
map @AI@ :set ai^M:map #Za @NOAI@^M:^M:"---- autoindent ON ----"^M
map @NOAI@ :set noai^M:map #Za @AI@^M:^M:"---- autoindent OFF ----"^M
map #Za @NOAI@
"==============================================================================
"TAB i  toggles between ignorecase and noignorecase
map @IC@ :set ic^M:map #Zi @NOIC@^M:^M:"--- case insensitive ---"^M
map @NOIC@ :set noic^M:map #Zi @IC@^M:^M:"--- case sensitive ---"^M
map #Zi @NOIC@
"==============================================================================
"TAB t  lists toggles (capital letter is toggle name)
map #Zt  :"MNEUMONICS: Autoindent; case Insensitive; Numbered editing"^M
"==============================================================================
" GENERAL NOTES I NEED TO ORGANIZE OR LOOK AT
"==============================================================================
" tried to map a key so all lowercase letters entered in insert mode would
" be  translated  to uppercase.  Another key would unmap them all.  Didn't
" work because vi considers you in insert mode on the ex : command line!
"==============================================================================
" Hard to find:
"/string/z  FIND AND PLACE AT SCREEN TOP (NICE FOR NEXT PAGE, CODE SECTION TOP.
"
" multiple sets can be on a line and can separate ex commands with a |.
" This is very powerful when mixed with the g and v commands.
" Very elaborate edits are possible (that you can source from a file):
" 'a;'bg/string/s/^/BEFORE^M/|?find above?|s/old/new/
"
" Commonly unused keys in vi command mode:
"         control characters ....... ^A ^I ^K ^O ^V ^W ^X
"         alphameric characters ....  g  K  q  v  V
"         punctuation characters ...  *  _  \  =
" Be cautious of control characters which sometimes interfere with %stty
" options and/or terminal functions.
"
" GRIPES
" o editor macros should be able to take parameters,
"   can simulate this by making scripts that create :source files.
" o #n should execute function key definition n, even if function key n defined
" o should be able to query and use current word
" o use vi commands in file to be :sourced
" o a built-in help facility such as the vax vms edt and eve editor has would
" o be nice for beginners.
" o The tilde command should work over a range.
" o no easy way to change terminal width (most versions now obey SIGWININFO
"   and so you can change window on an xterm or dxterm or other X11 terminal
"   emulator. On a plain vt100 you would have to go to line mode, change
"   term to vt100-w and manually change to 132 column mode or upgrade the
"   terminfo file to send the 132 initialization string and so on).
"   Most rlogin(1) pass SIGWININFO, most telnet(1) do not. This means when you
"   log into a remote machine you might have to use any of
"   stty lines 24 columns 80
"   export ROWS=24 COLUMNS=80
"   eval `resize` # for an xterm(1)
"   so that vi knows your window size. 24x80 is the "safe" window size if you
"   are having problems.
" o marks are lost that are contained in a region passed to a filter
"==============================================================================
" COMPARED TO CDC FSE:
" o No help or teach command (:!man vi doesn't quite do it)
" o No paragraph fill or centering capability (like .f and .c)
" o would be nice if could leave a message like FSE set announce from macros
"   like if could set ex prompt to any value (:set prompt='string of stuff')
" o a lot of things would be easier if had prompting and positional parameters
"   for macros
" o no equivalents to FSE split screen editing, set view offset, and alter
"   commands, or to a visible (highlited in inverse) marked range.
" o can't switch between terminal sizes (132 column, 44 lines) like FSE can
"   (Footnote: on DEC workstation, vi adjusts dynamically to xterm window sizes)
" o things like "locate all word upper" much harder with vi than FSE.
"   No easy locate [word] [ignorecase] like FSE lawu command.
" o No single procedure file (each :source needs a unique file) like FSEPROC.
" o termcap and vi information on using function keys seems very vague.
"   may only have ten functions if use termcap instead of terminfo.
"==============================================================================
" Really nice commands to remember:
"
" :g/string/#                         show all lines with string in them with line numbers
" :1,$g/^$/d                          delete all blank lines from line 1 to $ (end of file)
" :1,$g/  */s// /g                    replace multiple spaces with one space
" :[range]g/[string]/d"a              delete (or yank) lines containing
"                                     string into buffer a
" :[range]g!/[string]/d"a             delete lines NOT containing string into
"                                     buffer a
" :-m. or .m+                         switch current line with previous|next
" :f newbuffername                    change name of file being edited to a new name
" INTERFACING WITH SAVED FILES (FILES -NOT- IN EDITOR BUFFER(S))
" :w filename                         SAVE ENTIRE buffer to a new file
" :'a;'bw filename                    SAVING PART of buffer to a new file
" :'a;'bw! filename                   OVERWRITING a file with part of buffer
" :'a;'bw >>filename                  appending part of buffer to a file
" :r filename                         reading in a filename at CP
" SHELL INTERFACING
" :!cmd                      execute single shell command
" :sh                        execute multiple shell commands (start a subshell)
" :r!cmd                     output of command written into edit file at CP
" :'a;'b!cmd                 filter lines thru command(use text as input to
"                            command, replace text with output of command)
"                            cb,pr -o1,cut,paste,expand and many other
"                            filters can add almost any command to vi
" :w!cmd                     write lines to standard input of command
"                            :w! lpr -Pps (or lp -dps)
"==============================================================================
" NOTE: :map displays current user-defined map strings
"       To see insert-mode map! strings, use :map!
"==============================================================================
" NOTE: marked words don't seem to work correctly, especially when do
"       multiple puts using them.
" NOTE: what will drive you crazy trying to build multi-command lines
"       mixing ex and vi commands is prompt after :ex command that
"       says enter carriage return to continue will continue on
"       ANY next character.
"       may be why Hmd .... 'dz
"       does not pause, either
" NOTE: only one pause per :so read, may be able to put vi command
"       into :so file to do vi commands
"
" For paragraph fill. Nice if had "leave column 1-x cxx for FORTRAN,
" * for C comments, " for .exrc comments, whatever (A prefix/suffix string
" for each line while doing paragraph fill).
"
" depending on whether using Sys5 or Berkeley, several of these filters do
" different things, but check out editing functions you can add via
"asa,nasa,awk,cat,cb,sort,cut,paste,expand,unexpand,fold,pr,nl,tr
"
" NOTE: when setting marks with ex(1) the current file view is not changed.
"       When using vi you must make the desired location the current position.
"       The result is you can reduce screen repainting when setting marks not
"       on the screen if you use ex(1) instead of vi(1) commands.
"
" a trick to only get one carriage return prompt from a series of ex commands
" is not to delimit them with carriage return or esc, but with a |. Note
" to get | into a map sequence it must be entered in .exrc as ^V^V|
"==============================================================================
" These tips were in a file I was told was from Berkeley:
  "Vi macro management:
  "- if possible don't repeat character sequences in different macros, put them
  "  in their own macros;
  "- try to be concise, e.g. instead of "map @i :set noautoindent^V^M" use
  "  "map @i :se noai^V^M";
  "- don't try to solve difficult problems in vi, create appropriate shell
  "  scripts instead, to be invoked through maps;
  "- create specialized macro files, to be sourced only when appropriate,
  "  you don't need all your maps all the time, e.g. "map ^C :!cc % " isn't
  "  that useful when editing a letter to your friend; you might even create
  "  shell scripts to do the sourcing for you -
  "
  "        % cat ~/bin/cvi
  "        #!/bin/sh
  "        /usr/ucb/vi +"so $HOME/.cmaps" ${1+"$@"}
  "        %
  "
  "However, this script reveals an interesting bug: the source command will only
  "take place when the first EXISTENT file is read into the buffer!
  "A better idea than hacking the shell script is to define a standard macro
  "(in EXINIT) to source ~/.cmaps:
  "
  "        map\C :unm\C^V|so~/.cmaps^M
  "
  "No unnecessary spaces! :-)
  "When ~/.cmaps has been sourced, the `\C' macro can be deleted, hence the `unm'.
map Q :%s/........../mv/^M^[:!chmod a+w %^M:w!^M:!cd %;sh 00*;mv 00* ~/tmp^M
  "====================================================================================
"==============================================================================
" Handy commands for NOS/COS users migrating to UNICOS:
" change UPDATE "*CALL NAME" to "      include 'name.h'
" 1,$s/^\*CALL[, ]\(.*\)/      include '\L\1.h'/
"==============================================================================

Generated by John S. Urban .