Xref: utzoo comp.editors:923 comp.text:4882 comp.unix.questions:16151 comp.misc:6905 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!hellgate.utah.edu!cs.utexas.edu!uunet!mcsun!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.editors,comp.text,comp.unix.questions,comp.misc Subject: the reformatted Vi Reference (patchlevel 4) Message-ID: <3144@solo4.cs.vu.nl> Date: 5 Sep 89 02:23:32 GMT Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 600 Some small fixes, some additions (Diomidis & me), prints nicely (Blair). No use to post context diffs. :-) Your OS should have the `tr' (translate) command, else you must edit the CTRL_L assignment below to use a hard ^L. Enjoy. : This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb CTRL_L="`echo L | tr L '\14'`" echo Extracting 'vi.ref.4' sed -e 's/^X//' \ -e "s/^Control-L$/$CTRL_L/" > 'vi.ref.4' << '+ END-OF-FILE ''vi.ref.4' X X X X X X //////////////////////////////////////////////////////////////////////// X / VI REFERENCE (by maart@cs.vu.nl) / X //////////////////////////////////////////////////////////////////////// X X Warning: some vi versions don't support the more esoteric features X described in this document. You can edit/redistribute this document X freely, as long as you don't make false claims on original authorship. X X default values : 1 X ^X : x X [*] : * is optional X <*> : * must not be taken literally X : space X : carriage return X : linefeed X : horizontal tab X : escape X : your erase character X : your kill character X : your interrupt character X : an element in the range X N : number (* = allowed, - = not used) X CHAR : char unequal to | X WORD : word followed by || XControl-L X X X X X X ///////////////// X / move commands / X ///////////////// X X N | Command | Meaning X ---+--------------------+----------------------------------------------- X * | h | ^H | <*> chars to the left X * | j | | ^N | <*> lines downward X * | l | | <*> chars to the right X * | k | ^P | <*> lines upward X * | $ | to the end of line <*> from the cursor X - | ^ | to the first CHAR of the line X * | _ | to the first CHAR <*> - 1 lines lower X * | - | to the first CHAR <*> lines higher X * | + | | to the first CHAR <*> lines lower X - | 0 | to the first char of the line X * | | | to column <*> (: only to the endpoint!) X * | f | <*> s to the right (find) X * | t | till before <*> s to the right X * | F | <*> s to the left X * | T | till after <*> s to the left X * | ; | repeat latest "f"|"t"|"F"|"T" <*> times X * | , | idem in opposite direction X * | w | <*> words forward X * | W | <*> WORDS forward X * | b | <*> words backward X * | B | <*> WORDS backward X * | e | to the end of word <*> forward X * | E | to the end of WORD <*> forward X * | G | go to line <*> (default EOF) X * | H | to line <*> from top of the screen (home) X * | L | to line <*> from bottom of the screen (last) X - | M | to the middle line of the screen X * | ) | <*> sentences forward X * | ( | <*> sentences backward X * | } | <*> paragraphs forward X * | { | <*> paragraphs backward X - | ]] | to the next section (default EOF) X - | [[ | to the previous section (default begin of file) X - | ` | to the mark X - | ' | to the first CHAR of the line with the mark X - | `` | to the cursor position before the latest absolute X | jump (of which are examples "/" and "G") X - | '' | to the first CHAR of the line on which the cursor X | was placed before the latest absolute jump X - | / | to the next occurrence of X - | ? | to the previous occurrence of X - | n | repeat latest "/"|"?" (next) X - | N | idem in opposite direction X - | % | find the next bracket and go to its match X | (also { } and [ ]) XControl-L X X X X X X ///////////////////////// X / searching (see above) / X ///////////////////////// X X ^] | search in the tags file where the function X | under the cursor is defined (file, line) and X | go to it X :[x,y]g// | search globally [from line x to y] for X | and execute the "ex" on each occurrence X X /////////////////// X / undoing changes / X /////////////////// X X u | undo the latest change X U | undo all changes on a line, while not having X | moved off it (unfortunately) X :q! | quit vi without writing X :e! | re-edit a messed-up file X X /////////////////////////////////// X / appending text (end with ) / X /////////////////////////////////// X X * | a | <*> times after the cursor X * | A | <*> times at the end of line X * | i | <*> times before the cursor (insert) X * | I | <*> times before the first CHAR of the line X * | o | on a new line below the current (open) X | the count is only useful on a slow terminal X * | O | on a new line above the current X | the count is only useful on a slow terminal X * | > | shift the lines described by <*> one X | shiftwidth to the right (layout) X * | >> | shift <*> lines one shiftwidth to the right X * | ["]p | put the contents of the (default undo) X | buffer <*> times after the cursor; X | a buffer containing lines is put only once, X | below the current line X * | ["]P | put the contents of the (default undo) buffer <*> X | times before the cursor X | a buffer containing lines is put only once, above X | the current line X * | . | repeat latest command <*> times X | if the last command before a "." command X | references a numbered buffer, the buffer number X | is incremented first (and the count is ignored): X | X | "1pu.u.u.u.u - `walk through' buffers 1 X | through 5 X | "1P.... - restore them XControl-L X X X X X X ///////////////// X / deleting text / X ///////////////// X X Everything deleted can be stored into a buffer. This is achieved by X putting a " and a letter before the delete command. The X deleted text will be in the buffer with the used letter. If X is used as buffer name, the adjugate buffer will be augmented X instead of overwritten with the text. The undo buffer always X contains the latest change. Buffers "<1-9> contain the latest 9 X LINE deletions ("1 is most recent). X X * | x | delete <*> chars under and after the cursor X * | X | <*> chars before the cursor X * | d | from begin to endpoint of <*> X * | dd | <*> lines X - | D | the rest of the line X * | < | shift the lines described by <*> one X | shiftwidth to the left (layout) X * | << | shift <*> lines one shiftwidth to the left X * | . | repeat latest command <*> times X X ////////////////////////////////// X / changing text (end with ) / X ////////////////////////////////// X X * | r | replace <*> chars by - no X * | R | overwrite the rest of the line, X | appending change <*> - 1 times X * | s | substitute <*> chars X * | S | <*> lines X * | c | change from begin to endpoint of <*> X * | cc | <*> lines X * | C | the rest of the line and <*> - 1 next lines X * | = | if the option 'lisp' is set, this command X | will realign the lines described by <*> X | as though they had been typed with the option X | 'ai' set too X - | ~ | switch lower and upper cases X * | J | join <*> lines (default 2) X * | . | repeat latest command <*> times ("J" only once) X - | & | repeat latest "ex" substitute command, e.g. X | ":s/wrong/good" XControl-L X X X X X X /////////////////////////////////// X / substitute replacement patterns / X /////////////////////////////////// X X The basic metacharacters for the replacement pattern are `&' and `~'; X these are given as `\&' and `\~' when nomagic is set. Each instance X of `&' is replaced by the characters which the regular expression X matched. The meta- character `~' stands, in the replacement X pattern, for the defining text of the previous replacement X pattern. Other metasequences possible in the replacement pattern X are always introduced by the escaping character `\'. The sequence X `\n' (with `n' in [1-9]) is replaced by the text matched by the X n-th regular subexpression enclosed between `\(' and `\)'. The X sequences `\u' and `\l' cause the immediately following character X in the replacement to be converted to upper- or lower-case X respectively if this character is a letter. The sequences `\U' and X `\L' turn such conversion on, either until `\E' or `\e' is X encountered, or until the end of the replacement pattern. X X ////////////////////////////// X / remembering text (yanking) / X ////////////////////////////// X X With yank commands you can put " before the command, just as X with delete commands. Otherwise you only copy to the undo buffer. X The use of buffers is THE way of copying text to another X file; see the ":e " command. X X * | y | yank from begin to endpoint of <*> X * | yy | <*> lines X * | Y | idem (should be equivalent to "y$" though) X - | m | mark the cursor position with a letter X X //////////////////////////////////////// X / commands while in append|change mode / X //////////////////////////////////////// X X ^@ | if typed as the first character of the X | insertion, it is replaced with the previous X | text inserted (max. 128 chars), after which X | the insertion is terminated X ^V | deprive the next char of its special meaning X | (e.g. ) X ^D | one shiftwidth to the left X 0^D | remove all indentation on the current line X | (there must be no other chars on the line) X ^^D | idem, except that it is restored on the next line X ^T | one shiftwidth to the right X ^H | | one char back X ^W | one word back X | back to the begin of the change on the X | current line X | like XControl-L X X X X X X ///////////////////////////////////////////////// X / writing, editing other files, and quitting vi / X ///////////////////////////////////////////////// X X :q | quit vi, unless the buffer has been changed X :q! | quit vi without writing X :w | write the file X :w | write to the file X :w >> | append the buffer to the file X :w! | overwrite the file X :x,y w | write lines x through y to the file X :wq | write the file and quit vi, WITHOUT X | checking if the write has been X | successful (use "ZZ" instead) X ZZ | write if the buffer has been changed, and X | quit vi; if you have invoked vi with the "-r" X | option, you'd better write the file X | explicitly ("w" or "w!"), or quit the X | editor explicitly ("q!") if you don't want X | to overwrite the file - some versions of vi X | don't handle the "recover" option very well X :x | idem X :x! | ":w!" and ":q" X :e | edit another file without quitting vi - the X | buffers are not changed (except the undo X | buffer), so text can be copied from one X | file to another this way X :e! | idem, without writing the current buffer X :e# | edit the previous file X ^^ | idem X :rew | edit the first file (when "vi file1 file2 ...") X :rew! | idem, without writing the current buffer X :n [] | edit the next file X :n! [] | idem, without writing the current buffer XControl-L X X X X X X //////////////////// X / display commands / X //////////////////// X X ^G | give current line number and relative position X ^L | refresh the screen (sometimes "^P" or "^R") X ^R | sometimes vi replaces a deleted line by X | a '@', to be deleted by "^R" (also with X | option 'noredraw') X [*]^E | expose <*> more lines at bottom, cursor X | stays put (if possible) X [*]^Y | expose <*> more lines at top, cursor X | stays put (if possible) X [*]^D | scroll <*> lines downward X | (default the number of the previous scroll; X | initialization: half a page) X [*]^U | scroll <*> lines upward X | (default the number of the previous scroll; X | initialization: half a page) X [*]^F | <*> pages forward X [*]^B | <*> pages backward (in older versions "^B" only X | works without count) X X If in the next commands the field is present, the windowsize X will change to . The window will always be displayed at the X bottom of the screen. X X [*]z[wi] | put line <*> at the top of the window X | (default the current line) X [*]z[wi]+ | put line <*> at the top of the window X | (default the first line of the next page) X [*]z[wi]- | put line <*> at the bottom of the window X | (default the current line) X [*]z[wi]. | put line <*> in the centre of the window X | (default the current line) XControl-L X X X X X X //////////////////////////// X / mapping and abbreviation / X //////////////////////////// X X When mapping take a look at the options 'to' and 'remap' (below). X X :map | is interpreted as , e.g. X | ":map ^C :!cc %^V" to compile from within vi X | (vi replaces % with the current file name) X :map | show all mappings X :unmap | deprive of its mapping X | when vi complains about non-mapped macros X | (whereas no typos have been made), first do X | something like ":map Z", followed X | by ":unmap " ('Z' must not be a X | macro itself), or switch to "ex" mode first X :map! | mapping in append mode, e.g. X | ":map! \be begin^Vend;^VO" X | when is preceded by ^V, no X | mapping is done X :map! | show all append mode mappings X :unmap! | deprive of its mapping (see ":unmap") X :ab | whenever in append mode is followed X | by a breakpoint (e.g. or ','), it is X | interpreted as , e.g. ":ab p procedure" X | a char preceded by ^V is not considered X | a breakpoint X :ab | show all abbreviations X :unab | do not consider an abbreviation X | anymore (see ":unmap") X @ | consider the contents of the named register a X | command, e.g.: X | o0^D:s/wrong/good/"zdd X | explanation: X | o - open a new line X | 0^D - remove indentation X | :s/wrong/good/ - this input text is an X | "ex" substitute command X | - finish the input X | "zdd - delete the line just X | created into register 'z' X | now you can type @z to substitute `wrong' X | by `good' on the current line X @@ | repeat last register command XControl-L X X X X X X ///////////////////////////// X / switch and shell commands / X ///////////////////////////// X X Q | ^\ | | switch from vi to "ex" X : | an "ex" command can be given X :vi | switch from "ex" to vi X :sh | execute a subshell, back to vi by ^D X :! | execute a shell X :!! | repeat the last shell command X [*]! | the shell executes , with as standard X | input the lines described by <*>, X | next the standard output replaces those lines X | (think of cb, sort, nroff, etc.) X [*]!! | append to the last and execute it, X | using the lines described by the current X | <*> X [*]!! | give <*> lines as standard input to the X | shell , next let the standard output X | replace those lines X [*]!!! [] | use the previous (and append to it) X :x,y w ! | let lines x to y be standard input for X | (notice the space between 'w' and '!') X :r! | put the output of onto a new line X :r | read the file into the buffer XControl-L X X X X X X ////////////// X / vi startup / X ////////////// X X vi [file] : edit the file and display the first page X X The editor can be initialized by the shell variable EXINIT, which X looks like: X X EXINIT='||...' X : set options X map ... X ab ... X export EXINIT (in the Bourne shell) X X However, the list of initializations can also be put into a file. X If this file is located in your home directory, and is named X ".exrc" AND the variable EXINIT is NOT set, the list will be X executed automatically at startup time. If the 3 conditions are not X met, you have to give the execute command yourself: X X :source file X or X :so file X X On-line initializations can be given with "vi + file", e.g.: X X vi +x file | the cursor will immediately jump to line x X | (default last line) X vi +/ file | ~ to the first occurrence of X X You can start at a particular tag with: X X vi -t | starts in the right file in the right place X X Sometimes (e.g. if the system crashed while you were editing) it is X possible to recover files lost in the editor by "vi -r file". If X you just want to view a file by using vi, and you want to avoid any X change, instead of vi you can use the "view" or "vi -R" command: X the option 'readonly' will be set automatically (with ":w!" you can X override this option). XControl-L X X X X X X ////////////////////////////// X / the most important options / X ////////////////////////////// X X ai | autoindent - in append mode after a the X | cursor will move directly below the first X | CHAR on the previous line. However, if the X | option 'lisp' is set, the cursor will align X | at the first argument to the last open list. X aw | autowrite - write at every shell escape X | (useful when compiling from within vi) X dir= | directory - the directory for vi to make X | temporary files (default /tmp) X eb | errorbells - beeps when you goof X | (not on every terminal) X ic | ignorecase - no distinction between upper and X | lower cases when searching X lisp | redefine the following commands: X | "(", ")" - move backward (forward) over X | S-expressions X | "{", "}" - idem, but don't stop at atoms X | "[[", "]]" - go to previous (next) line X | beginning with a '(' X | see option 'ai' X list | is shown as '$', as '^I' X magic | some metachars can be used when searching: X | ^ - must begin the line X | $ - must end the line X | . - matches any char X | [a-z] - matches any char in the range X | [] - matches any char in X | [^] - matches any char not in X | * - 0 or more s X | \<\> - must be a word X nu | number - numbers before the lines X para= | paragraphs - every pair of chars in is X | considered a paragraph delimiter nroff macro X | (for "{" and "}"). X | a preceded by a '\' indicates that X | the previous char is a single letter X | macro. ":set para=P\ bp" introduces '.P' X | and '.bp' as paragraph delimiters. X | completely empty lines and section X | boundaries are paragraph boundaries too. X redraw | the screen remains up to date X remap | if on (default), macros are repeatedly X | expanded until they are unchanged. X | Example: if 'o' is mapped to 'O', and 'O' X | is mapped to 'I', then 'o' will map to 'I' X | if "remap" is set, else it will map to 'O'. X report=<*> | vi reports whenever e.g. a delete X | or yank command affects <*> or more lines X ro | readonly - the file is not to be changed X | however, ":w!" will override this option XControl-L X X X X X X sect= | sections - gives the section delimiters X | (for "[[" and "]]"); see option 'para', X | however a '{' as first char on a line also X | starts a section (as in C functions) X sh= | shell - which program is to be used for X | shell escapes X sw=<*> | shiftwidth - gives the shiftwidth (default sw=8) X sm | showmatch - whenever you append a ')', vi X | tries to show its match by putting the cursor X | for a moment onto it (also with { }) X terse | short error messages X to | timeout - if this option is set, append mode X | mappings will be interpreted only if they're X | typed fast enough X ts=<*> | tabstop - the length of a ; X | warning: this is only IN the editor, X | outside of it s have their normal X | length (default ts=8) X wa | writeany - no checks when writing (dangerous) X warn | warn you when you try to quit without writing X wi=<*> | window - the default number of lines vi shows X wm=<*> | wrapmargin - when in append mode vi X | automatically puts a whenever there is X | a or within columns from the X | right margin X ws | wrapscan - when searching, the end is X | considered `stuck' to the begin of the file X X :set