NOTICE: The article below is copyrighted. You can distribute it freely, but you must distribute it as is, with no changes, and with the copyright notice at the bottom. ----------------------------------------------------------------------- VI - THE WORLDLY EDITOR 1. Intro Whether you are an Internet surfer, a USENET aficionado, a UNIX(tm) programmer or a plain user in a mixed platform environment, the most common utility you are likely to encounter is the vi editor. It's everywhere, on every UNIX system, and it is employed for anything from code editing to typing an occasional email letter. To a traditional DOS or Mac user, vi seems foreign at first mainly because it sees text input command as any other editing instruction and does not allow stacking it with other commands which almost all DOS and Mac editors do allow. For example, when inserting text in DOS "EDIT", can you press PageDown to go down? Yes, naturally, you will say. Not in vi, however, since text inserting does not have any special ability to be mixed with other commands. In vi you would first end text inserting command by pressing "Esc" (that's how all text input commands are terminated) and then you would press Ctrl-F (for "Forward Page"). While it may seem counter-intuitive to DOS and Mac users in the beginning, it allows the use of single letter keystrokes as editing instructions, making vi not only a very fast editor, but also a very frugal one when used over the wire. This particular design model has also allowed the author to make commands easy to remember and easy to deduce once some of them are memorized. This easy inference is necessary in vi since its "bandwidth frugality" precluded it from having menus. When vi is first started, it expects commands, be it text input, deletions, changes, searches. Following the command, an argument usually needs to be given, for example, following command "i" (insert text at the cursor), one would type text and then end the command with "Esc". For deletion, one would press "d" and then an argument, for example "w" for "word", or "3w" for "three words" or "}" which in vi-speak means "to the end of the paragraph". If simple mnemonic commands are not sufficient, command line is provided through pressing ":". From there long commands can be executed to be applied to ranges of lines in text. Even external programs can be used as filters to process parts of the text. If that is still not sufficient, a multi-line command facilities can be employed after pressing "Q". 2. Commands Since the best way to learn is through exercise, below you will find a cheat-sheet with vi commands. If you do not have an access to the UNIX system yet, you can already start practicing by downloading a DOS version of vi (elvis) from one of the many anonymous ftp sites. vi cheat-sheet a. cursor movements (items below are sometimes called "objects"): h - left one character l - right one character j - down one line k - up one line w - right one word b - back one word $ - to the end of line 0 - to the beginning of the line ) - right one sentence ( - left one sentence } - right one paragraph { - left one paragraph Ctrl-F - forward one page Ctrl-B - back one page G - go to (without arguments, go to end of file) b. deleting: d - delete then add one of the cursor movement symbols to show what should be deleted, i.e.: d$ - delete to end of line d0 - delete to the beginning of the line d} - delete to the end of paragraph dd - delete delete (delete the whole line) x - delete character cursor is on c. other basic commands: r - replace one character ZZ - save and exit (hold down shift and press "z" twice) y - yank (copy into temporary buffer) then add cursor movement symbol to show what should be copied, for example: y) - copy to the end of sentence Y - yank line cursor is on p - paste below cursor line (deleted or copied text) P - paste above cursor line u - undo last editing command /sometext - search for "sometext" d. any command can take numeric argument before the name of "object", i.e.: 5dd - delete 5 lines beginning with cursor line (or) d5d - same 2dw - delete two words (or) d2w - delete two words c3w - change 3 words 3Ctrl-B - move up three pages 1G - go to the first line e. external commands can be performed on the selected text (in lines) if command is started with "!", i.e.: !}fmt - reformat paragraph to 72 columns f. command line (sometimes called "ex mode"): : g. in ex mode "set" command can be executed to customize editing environment, i.e.: :set all - will show the state of all options :set number - will show on the screen numbers of all lines :set autoindent // obvious h. in ex mode any ex command can be performed on the range of lines, i.e.: :18,24 del - delete from line 18 to line 24 :23,48 copy 17 - block from line 23 to 48 copy to line 17 :2,17 move 92 - block from line 2 to 17 move to line 92 i. in ex mode any external UNIX command can be performed on the range of lines if line range is superseded by "!": :11,16! sed -e "s/^/\/\*/" -e "s/$/\*\//" (the command above wraps the block of text with "C" style comments - /* text */. It can be done easier, but this is an example) :14,19! sort -r +3 (sort the table in reverse order by fourth column) j. file commands in ex mode: :r somefile - read in "somefile" :x - save and exit (if file is "Read Only", this command will exit without saving) :wq - write and quit (same as above) :w - write (save) :w somefile - save this file as "somefile" :q - quit without saving :q! - quit without saving if changes were made k. text input commands (all require "Esc" to terminate): i - insert text before the character cursor is on I - insert text at the beginning of the line a - append (insert text after the character cursor is on) A - append text to the end of the line c - change (replace previous text with new one) takes arguments just like the delete command - it is a fast and powerful way of changing original text - much more so than typical "overwrite" R - start overwriting text o - start entering text at the beginning of the new line below the cursor O - start entering text at the beginning of the new line above the cursor l. if in doubt, press "Esc" 3. Startup File Having explored vi commands somewhat, we are now ready to create a default editing environment through the use of .exrc (or elvis.rc if you use elvis DOS vi clone), the configuration file which resides in user's home directory (for DOS users simply set environment variable "home" to a directory where you wish to keep elvis.rc file). .exrc typically contains at least three types of entries: set commands to create preferred editing environment, map commands to assign functions or macros to keys, and ab commands to either map abbreviations or automatically correct common spelling errors. When mapping escape sequences of some keys, we may need to "quote" them, that is, to insert them literally. This can be accomplished in vi by issuing insert text command and pressing Ctrl-V before the key we wish to quote is pressed. Now let's look at a sample .exrc: set autoindent set wrapmargin=8 set ignorecase map #0 :w^M map #4 !}fmt^M ab teh the ab cutsomer customer Lines 1 and 2 set autoindent mode on and turn on wordwrap at column 72. Line 3 specifies that all searches are to be case insensitive. Lines 4 maps function key 10 to "save" command. Line 5 maps function key 4 to "reformat from the cursor position to the end of the paragraph". Finally, lines 6 and 7 map some common misspellings to the correct spelling. Note that ^M on lines 4 and 5 are created by pressing Ctrl-V and then hitting Ctrl-M. With a little creativity you can make vi look as personal as you wish. NOTE: After creating .exrc make sure that EXINIT environment variable is not set (type set at the command prompt) - it would overwrite whatever settings you entered into .exrc. Also make sure that .exrc contains no blank lines - they are not allowed. 4. Editing Multiple Files Editing multiple files in vi is possible in two different ways: - invoke vi with multiple files on the command line - use its ex command :e from within vi Once the files are loaded, movement from one file to another can be accomplished using following commands: - ex command :n for "next file" - ex command :e# for "previous file" - built-in command ^^ (Ctrl-^) for "last edited file, keep cursor on last edited line" 5. Using Named Buffers It is possible to copy or delete text from any file to a named buffer, and to keep as many as 26 of those buffers around for convenience. Buffers are created using lower case single letters (using upper case letter means "append to the existing buffer". The command beginning buffer operation is " (double quotation mark). Following it is the name of the buffer and then description of the operation to be performed: "ay} - yank (copy) from cursor to end of paragraph into buffer "a". If buffer exists, overwrite it. "A12d - delete 12 lines from cursor down and append it to the existing buffer "a". "ap - take contents of buffer "a" and paste it below cursor line. Notice that lower case name for a buffer causes it to be created every time a command is issued. A capital letter will append the new text to to the existing buffer. 6. Macros Buffers can also act as macros if they contain valid vi or ex commands. To execute such a macro, type: @a - where "a" is the name of the buffer Example: From a file containing definitions of complex macros, yank one paragraph (say, 20 lines) to a named buffer "a". Then return to a file you were originally editing and type @a. The commands contained in the buffer will be executed on the edited file. It is possible to make files act as vi macros. To do that, give an ex command: :so filename The most powerful macros, however, are created using programs combined into shell scripts (or DOS batch files), and acting as filters on the text sent to them from within vi. Such shell scripts or programs must take standard input and send results to standard output (which most UNIX tools do). With a little practice, using vi becomes a second nature. Thousands of happy users around the world attest to that. Copyright (C) 1994 Tony Porczyk - UNIX is a trademark of X/Open =============================== Here is some information I've found in the past... -------------------------------------------------- Key Normal Shift Control ---------------------------------------------------------------------- ESC | cancel command | N/A | N/A | RET | start of next line | N/A | N/A | SPACE | move right | N/A | N/A | ! | pipe through shell | N/A | N/A | " | refer to register | N/A | N/A | # | (ELV,incr) | N/A | N/A | $ | end of line | N/A | N/A | % | match bracket | N/A | N/A | & | repeat ex subst | N/A | N/A | ' | start marked line | N/A | N/A | ( | prev sentence | N/A | N/A | ) | next sentence | N/A | N/A | * | (ELV,nxt err) | N/A | N/A | + | start of next line | N/A | N/A | , | reverse last fFtT | N/A | N/A | - | start of prev line | N/A | N/A | . | repeat command | N/A | N/A | / | next match | N/A | N/A | 0 | first char of line | N/A | N/A | 1 | command count | N/A | N/A | 2 | command count | N/A | N/A | 3 | command count | N/A | N/A | 4 | command count | N/A | N/A | 5 | command count | N/A | N/A | 6 | command count | N/A | N/A | 7 | command count | N/A | N/A | 8 | command count | N/A | N/A | 9 | command count | N/A | N/A | : | exec an ex command | N/A | N/A | ; | repeat last fFtT | N/A | N/A | < | shift left | N/A | N/A | = | lisp fmt (not ELV) | N/A | N/A | > | shift right | N/A | N/A | ? | prev match | N/A | N/A | @ | execute register | N/A | N/A | a | ins after cursor | ins end of line | | b | prev word | prev WORD | back page | c | change area | change to eol | (break) | d | delete area | delete to eol | scroll down | e | next word end | next WORD end | move screen up | f | find right | find left | forward page | g | | goto line | file details | h | move left | top of screen | move left | i | ins before cursor | ins start of line | | j | move down | join line | move down | k | move up | (ELV,tag) | | l | move right | bottom of screen | refresh screen | m | mark position | middle of screen | start of next line | n | repeat search | reverse search | move down | o | open after line | open before line | | p | put after cursor | put before cursor | move up (PC,print) | q | | switch to ex | (flow control) | r | replace char | replace to eol | refresh screen | s | subst char | subst line | (flow control) | t | till right | till left | | u | undo | undo line | scroll up | v | | | | w | next word | next WORD | | x | delete char | delete prev char | | y | yank area | yank line | move screen down | z | window control | write & quit ZZ | (UNIX,suspend) | [ | prev sect [[ | N/A | cancel command ESC | \ | | N/A | | ] | next sect ]] | N/A | follow tag | ^ | start of line | N/A | edit alt file | _ | st nx ln (not ELV) | N/A | N/A | ` | goto mark | N/A | N/A | { | prev para | N/A | N/A | | | move to column | N/A | N/A | } | next para | N/A | N/A | ~ | toggle case | N/A | N/A | ---------------------------------------------------------------------- ///////////////// / contributions / ///////////////// Rich Salz Eamonn McManus Diomidis Spinellis Blair P. Houghton Rusty Haddock <{uunet,att,rutgers}!mimsy.umd.edu!fe2o3!rusty> Panos Tsirigotis David J. MacKenzie Kevin Carothers Dan Mercer Ze'ev Shtadler Paul Quare Dave Beyerl Lee Sailer David Gast /////////// / legenda / /////////// default values : 1 <*> : `*' must not be taken literally [*] : `*' is optional ^X : X : space : carriage return : linefeed : horizontal tab : escape : your erase character : your kill character : your interrupt character : an element in the range N : number (`*' = allowed, `-' = not appropriate) CHAR : char unequal to | WORD : word followed by || ///////////////// / move commands / ///////////////// N | Command | Meaning ---+--------------------+----------------------------------------------- * | h | ^H | | <*> chars to the left. * | j | | ^N | <*> lines downward. * | l | | <*> chars to the right. * | k | ^P | <*> lines upward. * | $ | To the end of line <*> from the cursor. - | ^ | To the first CHAR of the line. * | _ | To the first CHAR <*> - 1 lines lower. * | - | To the first CHAR <*> lines higher. * | + | | To the first CHAR <*> lines lower. - | 0 | To the first char of the line. * | | | To column <*> (: only to the endpoint). * | f | <*> s to the right (find). * | t | Till before <*> s to the right. * | F | <*> s to the left. * | T | Till after <*> s to the left. * | ; | Repeat latest `f'|`t'|`F'|`T' <*> times. * | , | Idem in opposite direction. * | w | <*> words forward. * | W | <*> WORDS forward. * | b | <*> words backward. * | B | <*> WORDS backward. * | e | To the end of word <*> forward. * | E | To the end of WORD <*> forward. * | G | Go to line <*> (default EOF). * | H | To line <*> from top of the screen (home). * | L | To line <*> from bottom of the screen (last). - | M | To the middle line of the screen. * | ) | <*> sentences forward. * | ( | <*> sentences backward. * | } | <*> paragraphs forward. * | { | <*> paragraphs backward. - | ]] | To the next section (default EOF). - | [[ | To the previous section (default begin of file). - | ` | To the mark. - | ' | To the first CHAR of the line with the mark. - | `` | To the cursor position before the latest absolute | jump (of which are examples `/' and `G'). - | '' | To the first CHAR of the line on which the cursor | was placed before the latest absolute jump. - | / | To the next occurrence of . - | ? | To the previous occurrence of . - | n | Repeat latest `/'|`?' (next). - | N | Idem in opposite direction. - | % | Find the next bracket and go to its match | (also with `{'|`}' and `['|`]'). ///////////////////////// / searching (see above) / ///////////////////////// :ta | Search in the tags file[s] where is | defined (file, line), and go to it. ^] | Use the name under the cursor in a `:ta' command. ^T | Pop the previous tag off the tagstack and return | to its position. :[x,y]g// | Search globally [from line x to y] for | and execute the `ex' on each occurrence. :[x,y]v// | Execute on the lines that don't match. /////////////////// / undoing changes / /////////////////// u | Undo the latest change. U | Undo all changes on a line, while not having | moved off it (unfortunately). :q! | Quit vi without writing. :e! | Re-edit a messed-up file. /////////////////////////////////// / appending text (end with ) / /////////////////////////////////// * | a | <*> times after the cursor. * | A | <*> times at the end of line. * | i | <*> times before the cursor (insert). * | I | <*> times before the first CHAR of the line * | o | On a new line below the current (open). | The count is only useful on a slow terminal. * | O | On a new line above the current. | The count is only useful on a slow terminal. * | > | Shift the lines described by <*> one | shiftwidth to the right. * | >> | Shift <*> lines one shiftwidth to the right. * | ["]p | Put the contents of the (default undo) buffer | <*> times after the cursor. | A buffer containing lines is put only once, | below the current line. * | ["]P | Put the contents of the (default undo) buffer | <*> times before the cursor. | A buffer containing lines is put only once, | above the current line. * | . | Repeat previous command <*> times. If the last | command before a `.' command references a | numbered buffer, the buffer number is | incremented first (and the count is ignored): | | "1pu.u.u.u.u - `walk through' buffers 1 | through 5 | "1P.... - restore them ///////////////// / deleting text / ///////////////// Everything deleted can be stored into a buffer. This is achieved by putting a `"' and a letter before the delete command. The deleted text will be in the buffer with the used letter. If is used as buffer name, the conjugate buffer will be augmented instead of overwritten with the text. The undo buffer always contains the latest change. Buffers <1-9> contain the latest 9 LINE deletions (`"1' is most recent). * | x | Delete <*> chars under and after the cursor. * | X | <*> chars before the cursor. * | d | From begin to endpoint of <*>. * | dd | <*> lines. - | D | The rest of the line. * | < | Shift the lines described by <*> one | shiftwidth to the left. * | << | Shift <*> lines one shiftwidth to the left. * | . | Repeat latest command <*> times. ////////////////////////////////// / changing text (end with ) / ////////////////////////////////// * | r | Replace <*> chars by - no . * | R | Overwrite the rest of the line, | appending change <*> - 1 times. * | s | Substitute <*> chars. * | S | <*> lines. * | c | Change from begin to endpoint of <*>. * | cc | <*> lines. * | C | The rest of the line and <*> - 1 next lines. * | = | If the option `lisp' is set, this command | will realign the lines described by <*> | as though they had been typed with the option | `ai' set too. - | ~ | Switch lower and upper cases | (should be an operator, like `c'). * | J | Join <*> lines (default 2). * | . | Repeat latest command <*> times (`J' only once). - | & | Repeat latest `ex' substitute command, e.g. | `:s/wrong/good'. - | :[x,y]s/

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

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

) and | `c' for `confirm' (type `y' to confirm a | particular substitution, else ). Instead | of `/' any punctuation CHAR unequal to | can be used as delimiter. /////////////////////////////////// / substitute replacement patterns / /////////////////////////////////// The basic meta-characters for the replacement pattern are `&' and `~'; these are given as `\&' and `\~' when nomagic is set. Each instance of `&' is replaced by the characters which the regular expression matched. The meta-character `~' stands, in the replacement pattern, for the defining text of the previous replacement pattern. Other meta-sequences possible in the replacement pattern are always introduced by the escaping character `\'. The sequence `\n' (with `n' in [1-9]) is replaced by the text matched by the n-th regular subexpression enclosed between `\(' and `\)'. The sequences `\u' and `\l' cause the immediately following character in the replacement to be converted to upper- or lower-case respectively if this character is a letter. The sequences `\U' and `\L' turn such conversion on, either until `\E' or `\e' is encountered, or until the end of the replacement pattern. ////////////////////////////// / remembering text (yanking) / ////////////////////////////// With yank commands you can put `"' before the command, just as with delete commands. Otherwise you only copy to the undo buffer. The use of buffers is THE way of copying text to another file; see the `:e ' command. * | y | Yank from begin to endpoint of <*>. * | yy | <*> lines. * | Y | Idem (should be equivalent to `y$' though). - | m | Mark the cursor position with a letter. //////////////////////////////////////// / commands while in append|change mode / //////////////////////////////////////// ^@ | If typed as the first character of the | insertion, it is replaced with the previous | text inserted (max. 128 chars), after which | the insertion is terminated. ^V | Deprive the next char of its special meaning | (e.g. ). ^D | One shiftwidth to the left, but only if | nothing else has been typed on the line. 0^D | Remove all indentation on the current line | (there must be no other chars on the line). ^^D | Idem, but it is restored on the next line. ^T | One shiftwidth to the right, but only if | nothing else has been typed on the line. ^H | | One char back. ^W | One word back. | Back to the begin of the change on the | current line. | Like (but you get a beep as well). ///////////////////////////////////////////////// / writing, editing other files, and quitting vi / ///////////////////////////////////////////////// In `:' `ex' commands - if not the first CHAR on the line - `%' denotes the current file, `#' is a synonym for the alternate file (which normally is the previous file). As first CHAR on the line `%' is a shorthand for `1,$'. Marks can be used for line numbers too: '. In the `:w'|`:f'|`:cd'|`:e'|`:n' commands shell meta-characters can be used. :q | Quit vi, unless the buffer has been changed. :q! | Quit vi without writing. ^Z | Suspend vi. :w | Write the file. :w | Write to the file . :w >> | Append the buffer to the file . :w! | Overwrite the file . :x,y w | Write lines x through y to the file . :wq | Write the file and quit vi; some versions quit | even if the write was unsuccessful! | Use `ZZ' instead. ZZ | Write if the buffer has been changed, and | quit vi. If you have invoked vi with the `-r' | option, you'd better write the file | explicitly (`w' or `w!'), or quit the | editor explicitly (`q!') if you don't want | to overwrite the file - some versions of vi | don't handle the `recover' option very well. :x [] | Idem [but write to ]. :x! [] | `:w![]' and `:q'. :pre | Preserve the file - the buffer is saved as if | the system had just crashed; for emergencies, | when a `:w' command has failed and you don't | know how to save your work (see `vi -r'). :f | Set the current filename to . :cd [

] | Set the working directory to | (default home directory). :cd! [] | Idem, but don't save changes. :e [+] | Edit another file without quitting vi - the | buffers are not changed (except the undo | buffer), so text can be copied from one file to | another this way. [Execute the `ex' command | (default `$') when the new file has been | read into the buffer.] must contain no | or . See `vi startup'. :e! [+] | Idem, without writing the current buffer. ^^ | Edit the alternate (normally the previous) file. :rew | Rewind the argument list, edit the first file. :rew! | Idem, without writing the current buffer. :n [+] [] | Edit next file or specify a new argument list. :n! [+] [] | Idem, without writing the current buffer. :args | Give the argument list, with the current file | between `[' and `]'. //////////////////// / display commands / //////////////////// ^G | Give file name, status, current line number | and relative position. ^L | Refresh the screen (sometimes `^P' or `^R'). ^R | Sometimes vi replaces a deleted line by a `@', | to be deleted by `^R' (see option `redraw'). [*]^E | Expose <*> more lines at bottom, cursor | stays put (if possible). [*]^Y | Expose <*> more lines at top, cursor | stays put (if possible). [*]^D | Scroll <*> lines downward | (default the number of the previous scroll; | initialization: half a page). [*]^U | Scroll <*> lines upward | (default the number of the previous scroll; | initialization: half a page). [*]^F | <*> pages forward. [*]^B | <*> pages backward (in older versions `^B' only | works without count). If in the next commands the field is present, the windowsize will change to . The window will always be displayed at the bottom of the screen. [*]z[wi] | Put line <*> at the top of the window | (default the current line). [*]z[wi]+ | Put line <*> at the top of the window | (default the first line of the next page). [*]z[wi]- | Put line <*> at the bottom of the window | (default the current line). [*]z[wi]^ | Put line <*> at the bottom of the window | (default the last line of the previous page). [*]z[wi]. | Put line <*> in the centre of the window | (default the current line). //////////////////////////// / mapping and abbreviation / //////////////////////////// When mapping take a look at the options `to' and `remap' (below). :map | is interpreted as , e.g. | `:map ^C :!cc %^V' to invoke `cc' (the C | compiler) from within the editor | (vi replaces `%' with the current file name). :map | Show all mappings. :unmap | Deprive of its mapping. When vi | complains about non-mapped macros (whereas no | typos have been made), first do something like | `:map Z', followed by | `:unmap ' (`Z' must not be a macro | itself), or switch to `ex' mode first with `Q'. :map! | Mapping in append mode, e.g. | `:map! \be begin^Vend;^VO'. | When in append mode is preceded by | `^V', no mapping is done. :map! | Show all append mode mappings. :unmap! | Deprive of its mapping (see `:unmap'). :ab | Whenever in append mode is preceded and | followed by a breakpoint (e.g. or `,'), it | is interpreted as , e.g. | `:ab ^P procedure'. A `^V' immediately | following inhibits expansion. :ab | Show all abbreviations. :unab | Do not consider an abbreviation | anymore (see `:unmap'). @ | Consider the contents of the named register a | command, e.g.: | o0^D:s/wrong/good/"zdd | Explanation: | o - open a new line | 0^D - remove indentation | :s/wrong/good/ - this input text is an | `ex' substitute command | - finish the input | "zdd - delete the line just | created into register `z' | Now you can type `@z' to replace `wrong' | with `good' on the current line. @@ | Repeat last register command. ///////////////////////////// / switch and shell commands / ///////////////////////////// Q | ^\ | | Switch from vi to `ex'. : | An `ex' command can be given. :vi | Switch from `ex' to vi. :sh | Execute a subshell, back to vi by `^D'. :[x,y]! | Execute a shell [on lines x through y; | these lines will serve as input for and | will be replaced by its standard output]. :[x,y]!! [] | Repeat last shell command [and append ]. :[x,y]! ! [] | Use the previous command (the second `!') in a | new command. [*]! | The shell executes , with as standard | input the lines described by <*>, | next the standard output replaces those lines | (think of `cb', `sort', `nroff', etc.). [*]!! | Append to the last and execute it, | using the lines described by the current | <*>. [*]!! | Give <*> lines as standard input to the | shell , next let the standard output | replace those lines. [*]!!! [] | Use the previous [and append to it]. :x,y w ! | Let lines x to y be standard input for | (notice the between the `w' and the `!'). :r! | Put the output of onto a new line. :r | Read the file into the buffer. :r | Read the file into the buffer. ////////////// / vi startup / ////////////// vi [] | Edit the files, start with the first page of | the first file. The editor can be initialized by the shell variable `EXINIT', which looks like: EXINIT='||...' : set options map ... ab ... export EXINIT (in the Bourne shell) However, the list of initializations can also be put into a file. If this file is located in your home directory, and is named `.exrc' AND the variable `EXINIT' is NOT set, the list will be executed automatically at startup time. However, vi will always execute the contents of a `.exrc' in the current directory, if you own the file. Else you have to give the execute (`source') command yourself: :so file In a `.exrc' file a comment is introduced with a double quote character: the rest of the line is ignored. Exception: if the last command on the line is a `map[!]' or `ab' command or a shell escape, a trailing comment is not recognized, but considered part of the command. On-line initializations can be given with `vi + file', e.g.: vi +x file | The cursor will immediately jump to line x | (default last line). vi +/ file | Jump to the first occurrence of . You can start at a particular tag with: vi -t | Start in the right file in the right place. Sometimes (e.g. if the system crashed while you were editing) it is possible to recover files lost in the editor by `vi -r file'. A plain `vi -r' command shows the files you can recover. If you just want to view a file by using vi, and you want to avoid any change, instead of vi you can use the `view' or `vi -R' command: the option `readonly' will be set automatically (with `:w!' you can override this option). ////////////////////////////// / the most important options / ////////////////////////////// ai | autoindent - In append mode after a the | cursor will move directly below the first | CHAR on the previous line. However, if the | option `lisp' is set, the cursor will align | at the first argument to the last open list. aw | autowrite - Write at every shell escape | (useful when compiling from within vi). dir= | directory - The directory for vi to make | temporary files (default `/tmp'). eb | errorbells - Beeps when you goof | (not on every terminal). ic | ignorecase - No distinction between upper and | lower cases when searching. lisp | Redefine the following commands: | `(', `)' - move backward (forward) over | S-expressions | `{', `}' - idem, but don't stop at atoms | `[[', `]]' - go to previous (next) line | beginning with a `(' | See option `ai'. list | is shown as `$', as `^I'. magic | If this option is set (default), the chars `.', | `[' and `*' have special meanings within search | and `ex' substitute commands. To deprive such | a char of its special function it must be | preceded by a `\'. If the option is turned off | it's just the other way around. Meta-chars: | ^ - must begin the line | $ - must end the line | . - matches any char | [a-z] - matches any char in the range | [^a-z] - any char not in the range | [] - matches any char in | [^] - any char not in | * - 0 or more s | \< - must begin a word | \> - must end a word modeline | When you read an existing file into the buffer, | and this option is set, the first and last 5 | lines are checked for editing commands in the | following form: | | vi:set options|map ...|ab ...|!...: | | Instead of a can be used, instead of | `vi' there can be `ex'. Warning: this option | could have nasty results if you edit a file | containing `strange' modelines. nu | number - Numbers before the lines. para= | paragraphs - Every pair of chars in is | considered a paragraph delimiter nroff macro | (for `{' and `}'). A preceded by a `\' | indicates the previous char is a single letter | macro. `:set para=P\ bp' introduces `.P' and | `.bp' as paragraph delimiters. Empty lines and | section boundaries are paragraph boundaries | too. redraw | The screen remains up to date. remap | If on (default), macros are repeatedly | expanded until they are unchanged. | Example: if `o' is mapped to `A', and `A' | is mapped to `I', then `o' will map to `I' | if `remap' is set, else it will map to `A'. report=<*> | Vi reports whenever e.g. a delete | or yank command affects <*> or more lines. ro | readonly - The file is not to be changed. | However, `:w!' will override this option. sect= | sections - Gives the section delimiters (for `[[' | and `]]'); see option `para'. A `{' beginning a | line also starts a section (as in C functions). sh= | shell - The program to be used for shell escapes | (default `$SHELL' (default `/bin/sh')). sw=<*> | shiftwidth - Gives the shiftwidth (default 8 | positions). sm | showmatch - Whenever you append a `)', vi shows | its match if it's on the same page; also with | `{' and `}'. If there's no match at all, vi | will beep. taglength=<*> | The number of significant characters in tags | (0 = unlimited). tags= | The space-separated list of tags files. terse | Short error messages. to | timeout - If this option is set, append mode | mappings will be interpreted only if they're | typed fast enough. ts=<*> | tabstop - The length of a ; warning: this is | only IN the editor, outside of it s have | their normal length (default 8 positions). wa | writeany - No checks when writing (dangerous). warn | Warn you when you try to quit without writing. wi=<*> | window - The default number of lines vi shows. wm=<*> | wrapmargin - In append mode vi automatically | puts a whenever there is a or | within columns from the right margin | (0 = don't put a in the file, yet put it | on the screen). ws | wrapscan - When searching, the end is | considered `stuck' to the begin of the file. :set