SECTION A ////////////////////////////////////////////////////// / COMMAND REFERENCE FOR OAK HILL VI AND PERSONAL VI* / ////////////////////////////////////////////////////// Section Code Section Topic Basic Command Examples ============================================================================= A ..... Section Code Listing .. (This screen) B ..... Legenda ............... Syntax notations C ..... Vi Startup ............ vi file[s] vi +cmd file[s] D ..... Moving Around ......... h j k l fx Fx tx Tx 1G E ..... Searching ............. /pat/ ?pat? n N / ? F ..... Adding New Text ....... i a o I A O p P G ..... Deleting Text ......... dd d'a ndd D H ..... Changing Text ......... c C s S I ..... Remembering Text ...... yy y'a nyy Y J ..... Other Commands ........ :fillp :sh K ..... Write, Quit, Edit New . :w :e :n :tag ZZ L ..... Map(!) and Abbrev ..... :map ;s :s/Sam/Bill/ M ..... Setting Options ....... :set noai :set wm This reference does not show all commands and contains only brief descriptions. Please see manual for details. * Adapted from "Vi Reference" by Maarten Litmaath SECTION B /////////// / Legenda / /////////// default values : 1 <*> : `*' must not be taken literally [*] : `*' is optional ^X : X : space : carriage return : linefeed : horizontal tab : escape : your erase character : your interrupt character : an element in the range N : number (`*' = allowed, `-' = not appropriate) CHAR : char that is not or WORD : word that is followed by or or SECTION C ////////////// / vi startup / ////////////// vi [] | Edit the files, start with the first page of | the first file. The editor can be initialized by a single 'colon' command in the environment variable `EXINIT', which looks like: EXINIT='' However, an unlimited list of initializations can also be put into a file called EXRC. This list will override the EXINIT variable. On-line initializations can be given with `vi + file', e.g.: vi +x file | The cursor will immediately jump to line x SECTION D ///////////////// / Moving Around / ///////////////// N | Command | Meaning ---+--------------------+----------------------------------------------- * | h | ^H | <*> chars to the left. * | j | <*> lines downward. * | l | | <*> chars to the right. * | k | <*> lines upward. * | $ | To the end of line <*> from the cursor. - | ^ | To the first CHAR of the line. * | - | To the first CHAR <*> lines higher. * | + | | To the first CHAR <*> lines lower. - | 0 | To the first char of the line. * | | | To column <*> * | 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. * | , | Same as above but 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 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 matching parenthesis or bracket ^G | Give file name, status, current line number | and relative position. ^L | Refresh the screen in case of display corruption [*]^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). [*]z | Put line <*> at the top of the window | (default the current line). [*]z+ | Put line <*> at the top of the window | (default the first line of the next page). [*]z- | Put line <*> at the bottom of the window | (default the current line). [*]z^ | Put line <*> at the bottom of the window | (default the last line of the previous page). [*]z. | Put line <*> in the centre of the window | (default the current line). SECTION E ///////////// / Searching / ///////////// - | / | Jump to the next occurrence of . - | ? | Jump to the previous occurrence of . - | n | Repeat latest `/' or `?' command - | N | Same as above but search in opposite direction. :ta | Search in the tags file where is | defined (file, line), and go to it. ^] | Use the name under the cursor in a `:ta' command. SECTION F //////////////////////////////////// / Adding New Text (end with ) / //////////////////////////////////// - | | Exit append mode, return to command mode - | u | Undo the latest text change command - | 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. * | >'a | Shift the lines from the current line to the | line marked 'a' one shiftwidth to the right. * | >> | Shift <*> lines one shiftwidth to the right. - | ["]p | Put the contents of the (default undo) buffer | after the cursor. | A buffer containing lines is put 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 text change command. | Special commands while in append mode: ^V | Deprive the next char of its special meaning | (e.g. ). ^D | One shiftwidth to the left. ^H | | One char back. ^W | One word back. SECTION G ///////////////// / 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. * | x | Delete <*> chars under and after the cursor. * | X | Delete <*> chars before the cursor. * | d | From begin to endpoint of <*>. * | dd | Delete <*> lines. - | D | The rest of the line. - | <'x | Shift the lines from the current line to the | line marked 'x' one shiftwidth to the left. * | << | Shift <*> lines one shiftwidth to the left. * | . | Repeat latest command <*> times. === EXAMPLES === 4dd Deletes 4 lines d'a Deletes lines from current line to the one marked 'a' de Deletes to end of current word dE Deletes to end of current WORD SECTION H ////////////////////////////////// / Changing Text (end with ) / ////////////////////////////////// - | r | Replace current char by - no . - | R | Overwrite the current line * | s | Substitute <*> chars. * | S | Substitute <*> lines. * | c | Change from begin to endpoint of <*>. * | cc | Change <*> lines. * | C | The rest of the line and <*> - 1 next lines. - | ~ | Switch lower and upper case for current character - | J | Join 2 lines - | . | Repeat latest text change command - | & | Repeat latest `ex' substitute command, e.g. | `:s/wrong/good' for current line only - | :[x,y]s/

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

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

) SECTION I ////////////////////////////// / 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 | Same as above - | m | Mark cursor position with letter from 'a' to 'z'. SECTION J ////////////////////////////////// / Substitutions & Other Commands / ////////////////////////////////// :sh | Execute a subshell, back to vi with | :fillp | Fill ("format") the text in the paragraph | in which the cursor sits. A "paragraph" | is a section of text delimited by blank | lines or lines that begin with a period. :rfillp | Same as above, but each sentence begins | on a new line. | ! | The shell executes , with as standard | input the lines delimited by the current | line and the line . Typically | is a line marked with an address like 'a. :r | Read the file into the buffer. SECTION K ///////////////////////////////////////////////// / Writing, Editing Other Files, and Quitting Vi / ///////////////////////////////////////////////// In `:' `ex' commands `%' denotes the current file, `#' is a synonym for the alternate file (which normally is the previous file). 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. :w | Write the file. :w | Write to the file . :we | Write current file and edit 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; ZZ | Write if the buffer has been changed, and | quit vi. :x [] | Same as above [but write to ]. :x! [] | `:w![]' and `:q'. :f | Set the current filename to . :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! [+] | Same as above, 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 `]'. SECTION L //////////////////////////// / Mapping and Abbreviation / //////////////////////////// When mapping take a look at the options `to' and `remap' (below). :map | is interpreted as as if the | commands in had been entered from the | keyboard :map | Show all mappings. :unmap | Deprive of its mapping. | :map! | is interpreted as if had been | entered in input mode, that is, the | characters in will be instantly | replaced by :map! | Show all input mode mappings. :unmap! | Deprive of its mapping (see `:unmap'). | :ab | Whenever in input mode is preceded and | followed by space or punctuation, | is replaced by . :ab | Show all abbreviations. :unab | Do not consider an abbreviation | anymore (see `:unmap'). | @ | Consider the contents of the named register a | command, e.g.: | o:s/wrong/good/"ayy | Explanation: | o - open a new line | :s/wrong/good/ - this input text is an | `ex' substitute command | - finish the input | "add - yank the line just | created into register `a' | Now you can type `@a' to replace `wrong' | with `good' on the current line. @@ | Repeat last register command. SECTION M ////////////////////////////// / The Most Important Options / ////////////////////////////// :set | Show all options and their values. :set all | Show all options and their values. | :set ai | autoindent - In append mode after a the :set noai | 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. | :set aw | autowrite - Write at every shell escape :set noaw | noautowrite - do not write at every shell escape | :set beep | Audibly beeps when you goof :set nobeep | Visually flashes "BEEP" when you goof | (not on every terminal). | :set colors=[bright] foreground [on] background | Sets screen colors. "foreground" & "background" | may be black, red, green, yellow, blue, | magenta, cyan, or white. The "bright" modifier | is optional. Recommended selections are | bright white on blue or bright yellow on | yellow. | :set cursor=underscore | Set cursor to flashing underscore or flashing :set cursor=box | box. Choosing "inbox" will produce underscore :set cursor=inbox | in command mode and flashing box in input mode. | :set ic | ignorecase - No distinction between upper and :set noic | lower cases when searching. | :set magic | If this option is set (default), the chars `.', :set nomagic | `[' 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 :set nu | Show line numbers with each line :set nonu | Do not show line numbers with each line | :set rmar=n | Set right margin for text filling. | :set sect= | sections - Gives the section delimiters (for `[[' | and `]]'); see option `para'. A `{' beginning a | line also starts a section (as in C functions). :set ts=<*> | tabstop - The length of a ; warning: this is | only IN the editor, outside of it s have | their normal length (default 8 positions). :set 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). :set ws | wrapscan - When searching, wrap around from | end of file back to the beginning :set nows | do not wrap when searching |