Xref: utzoo comp.editors:981 comp.unix.questions:16775 comp.text:5163 comp.misc:7078 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!ctrsol!ginosko!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.editors,comp.unix.questions,comp.text,comp.misc Subject: Vi Reference - version 6 Message-ID: <3505@solo10.cs.vu.nl> Date: 5 Oct 89 06:49:50 GMT Expires: 2 Nov 92 05:00:00 GMT Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 638 It'll never end. Many Minor Modifications, some additions. A patch would be twice as big. Still `old' format (what happened to you, Kevin?). 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.6' sed -e 's/^X//' \ -e "s/^Control-L$/$CTRL_L/" > 'vi.ref.6' << '+ END-OF-FILE ''vi.ref.6' 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 appropriate) 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 with `{'|`}' and `['|`]'). XControl-L X X X X X X ///////////////////////// X / searching (see above) / X ///////////////////////// X X :ta | Search in the tags file where is X | defined (file, line), and go to it. X ^] | Use the name under the cursor in a `:ta' command. X :[x,y]g// | Search globally [from line x to y] for X | and execute the `ex' on each occurrence. X :[x,y]v// | Execute on the lines that don't match. 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) buffer X | <*> 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, X | above the current line. X * | . | Repeat previous 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'. X - | :[x,y]s/

//| Substitute (on lines x through y) the pattern X |

(default the last pattern) with . Useful X | flags are `g' for `global' (i.e. change every X | non-overlapping occurrence of

) and `c' for X | `confirm' (type `y' to confirm a particular X | substitution, else ). Instead of `/' any X | punctuation CHAR unequal to can be used as X | delimiter. XControl-L X X X X X X /////////////////////////////////// X / substitute replacement patterns / X /////////////////////////////////// X X The basic meta-characters 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 meta-sequences 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, but 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 In `:' `ex' commands `%' denotes the current file, `#' is a synonym for X the alternate file (which normally is the previous file). X Marks can be used for line numbers too: '. X In the `:w'|`:f'|`:cd'|`:e'|`:n' commands shell meta-characters can be X used. X X :q | Quit vi, unless the buffer has been changed. X :q! | Quit vi without writing. X ^Z | Suspend vi. 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; some versions quit X | even if the write was unsuccessful! X | 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 [but write to ]. X :x! [] | `:w![]' and `:q'. X :pre | Preserve the file - the buffer is saved as if X | the system had just crashed; for emergencies, X | when a `:w' command has failed and you don't X | know how to save your work (see `vi -r'). X :f | Set the current filename to . X :cd [

] | Set the working directory to X | (default home directory). X :cd! [] | Idem, but don't save changes. 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 file to X | another this way. [Execute the `ex' command X | (default `$') when the new file has been X | read into the buffer.] must contain no X | or . See `vi startup'. X :e! [+] | Idem, without writing the current buffer. X ^^ | Edit the alternate (normally the previous) file. X :rew | Rewind the argument list, edit the first file. X :rew! | Idem, without writing the current buffer. X :n [+] [] | Edit next file or specify a new argument list. X :n! [+] [] | Idem, without writing the current buffer. X :args | Give the argument list, with the current file X | between `[' and `]'. XControl-L X X X X X X //////////////////// X / display commands / X //////////////////// X X ^G | Give file name, status, current line number X | and relative position. X ^L | Refresh the screen (sometimes `^P' or `^R'). X ^R | Sometimes vi replaces a deleted line by a `@', X | to be deleted by `^R' (see option `redraw'). 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. When vi X | complains about non-mapped macros (whereas no X | typos have been made), first do something like X | `:map Z', followed by `:unmap ' X | (`Z' must not be a macro itself), or switch to X | `ex' mode first with `Q'. 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 preceded and X | followed by a breakpoint (e.g. or `,'), it X | is interpreted as , e.g. `:ab p procedure'. X | A `^V' immediately following inhibits X | expansion. 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 | with `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 :[x,y]! | Execute a shell [on lines x through y; X | these lines will serve as input for and X | will be replaced by its standard output]. X :[x,y]!! [] | Repeat last shell command [and append ]. X :[x,y]! ! [] | Use the previous command (the second `!') in a X | new 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 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 [] | Edit the files, start with the first page of X | the first file. 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 `.exrc' X AND the variable `EXINIT' is NOT set, the list will be executed X automatically at startup time. However, vi will always execute the X contents of a `.exrc' in the current directory, if you own the file. X Else 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 | Start 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 | If this option is set (default), the chars `.', X | `[' and `*' have special meanings within search X | and `ex' substitute commands. To deprive such a X | char of its special function it must be preceded X | by a `\'. If the option is turned off it's just X | the other way around. Meta-chars: 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 `}'). A preceded by a `\' X | indicates the previous char is a single letter X | macro. `:set para=P\ bp' introduces `.P' and X | `.bp' as paragraph delimiters. Empty lines and X | section 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 `A', and `A' X | is mapped to `I', then `o' will map to `I' X | if `remap' is set, else it will map to `A'. 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 (for `[[' X | and `]]'); see option `para'. A `{' beginning a X | line also starts a section (as in C functions). X sh= | shell - The program to be used for shell escapes X | (default `$SHELL' (default `/bin/sh')). X sw=<*> | shiftwidth - Gives the shiftwidth (default 8 X | positions). X sm | showmatch - Whenever you append a `)', vi shows X | its match if it's on the same page; also with X | `{' and `}'. If there's no match, vi will beep. 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 ; warning: this is X | only IN the editor, outside of it s have X | their normal length (default 8 positions). 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 - In append mode vi automatically X | puts a whenever there is a or X | within columns from the right margin. X ws | wrapscan - When searching, the end is X | considered `stuck' to the begin of the file. X X :set