VI: All help refers to VISUAL mode, unless a preceding colon (:) is specified. get this info with :help on PC, or :viusage (on nvi with FreeBSD) Invocation vi file ; Edit at first line of 'file' vi file1 file2 ; Edit file1. Edit file2 via :n vi [options] file ; As above, but with Command Line Options Command Line Options +n ; Edit at line n + ; Edit at last line +/pattern ; Edit at line containing 'pattern' -R ; open file(s) in read-only mode -c ; Use line-oriented command mode -e ; ... restricted 'edit' mode. -l ; Enable 'lisp' and 'showmatch' options -wn ; Specify window size of 'n' lines -? ; Print a summary of all command line options -- ; End processing of command line options Exiting ZZ ; Exit visual mode, saving changes :x ; Exit saving changes :wq ; Write buffer, then quit. :w ; Write buffer to original file :w file ; Write buffer to 'file' :w>> file ; Append to 'file' :n,mw file ; Write lines 'n' through 'm' to 'file' :q ; Quit out of editor :q! ; Quit discarding changes :e! ; Reedit file, discarding changes Setting Options :set all ; Prints all option settings :set option ; Enables option 'option' :set nooption ; Disables option 'option' :set option? ; Prints current value of 'option' :set ; Prints modified options Text Input i ; Insert before cursor I ; Insert before first non-blank on line a ; Append after cursor A ; Append at end of line o ; Open and insert at line below O ; Open and insert at line above ESCape key ; Terminates Input mode. Insert Mode Commands Control-@ ; Repeat Last Insertion Control-W ; Erase last word entered Control-H ; Erase last character entered DELete or Backspace ; Same as Control-H Control-U ; Erase entire line Control-D ; Backtab over 'autoindent' 0Control-D ; Kill all 'autoindent' ^Control-D ; Kill 'autoindent' on current line only Control-V ; Next character literal(to insert control code) Screen Adjustment Control-L ; Clear and redraw screen Control-R ; Redraw only if @ (deleted) lines zCR ; Redraw, current line at top of page z. ; Redraw, current line at center of page z- ; Redraw, current line at bottom of page /pattern/z- ; Redraw, line containing 'pattern' at bottom of page zn. ; Redraw, set new window size of 'n' lines Control-E ; Scroll down 1 line Control-Y ; Scroll up 1 line Control-F ; Scroll forward one screen Control-B ; Scroll backward one screen Control-D ; Scroll down half screen Control-U ; Scroll up half screen Cursor Motion H ; Move cursor to top of page M ; Move cursor to middle of page L ; Move cursor to last line of page + ; Move cursor to next line at first non-white character - ; Move cursor to previous line at first non-white down-arrow or j ; Move cursor down one line, staying in same column up-arrow or k ; Move cursor up one line, staying in same column left-arrow or h ; Move cursor to the left right-arrow or l; Move cursor to the right 0 ; Move cursor to beginning of line ^ ; Move cursor to beginning of line (first non-white) $ ; Move cursor to the end of line n| ; Move cursor to column 'n' Control-H ; Same as left-arrow File Motion G ; Last line of file nG ; Line 'n' of file /pattern ; Next line containing 'pattern' ?pattern ; Previous line containing 'pattern' n ; Next / or ? N ; previous / or ? /pattern/+n ; 'n'th line after line containing 'pattern' ?pattern?-n ; 'n'th line before line containing 'pattern' ) ; Next sentence ( ; Preceding sentence } ; Next paragraph { ; Preceding paragraph ]] ; Next section/function [[ ; Preceding section/function `` ; Previous context '' ; Previous context at first non-white in line Search Patterns ^ ; Beginning of line $ ; End of line . ; Any character * ; Zero or more of previous character [A-Z] ; Matches any character from A to Z [abc] ; Matches a, b, or c [^abc] ; Matches any character BUT a, b or c \ ; escape character for literal: \ / $ . ^ [ ' & * | ~ \< ; Beginning of word \> ; End of word Marking Position mx ; Mark current position with locator 'x' `x ; Return to position at locator 'x' 'x ; ... at first non-white in line Yank and Put yy or Y ; Yank line to buffer yw ; Yank word to buffer nyy or nY ; Yank 'n' lines to buffer p ; Put back lines below cursor P ; Put back lines above cursor "xy ; Yank line to buffer 'x' "xp ; Put from buffer 'x' Substitution stext ; Substitutes 'text' for character until ESCape S ; Substitute for entire line until ESCape :s/X/Y/opt ; Substitute 'Y' for first occurrence of 'X' ; Options: g - Change every currence in line ; c - Confirm each change ; p - Print each change (Command mode only) & ; Repeat last :substitute command :g/X/s//Y/opt ; Globally find the first 'X' on each line and ; substitute 'Y' for the string 'X' Deleting Text x ; Delete character under cursor nx ; Delete 'n' characters X ; Delete character before cursor dw ; Delete word ndw ; Delete 'n' words dd ; Delete entire line dtx ; Delete to 'x' in current line D ; Delete to end of line d/pattern ; Delete up to 'pattern' d?pattern ; Delete back to 'pattern' d`x ; Delete to marked location 'x' d'x ; Delete current line and to line which contains ; marked location 'x' d) ; Delete to end of sentence d( ; Delete to beginning of sentence d} ; Delete to end of paragraph d{ ; Delete to beginning of paragraph d]] ; Delete to end of section d[[ ; Delete to beginning of section Changing Text cw ; Change word ncw ; Change 'n' words cc ; Change entire line ncc ; Change 'n' lines C ; Change to end of current line c/pattern ; Change up to 'pattern' c?pattern ; Change back to 'pattern' c`x ; Change to marked location 'x' c'x ; Change current line and to line which contains ; marked location 'x' c) ; Change to end of sentence c( ; Change to beginning of sentence c} ; Change to end of paragraph c{ ; Change to beginning of paragraph c]] ; Change to end of section c[[ ; Change to beginning of section rx ; Replace character with 'x' R ; Replace all characters until ESCape is entered Word and Within Line Motions w ; Move cursor forward by one word W ; ... including any punctuation b ; Move cursor backward by one word B ; ... including any punctuation e ; Move cursor forward to end of word E ; ... including any punctuation fx ; Search current line (only) forward for 'x' Fx ; Search current line (only) backward for 'x' ; ; Repeat last 'f' or 'F' , ; Reverse of last 'f' or 'F' Undo u ; Undo last change U ; Restore current line "np ; Retrieve from buffer 'n' (1-9 and a-z) "n1pu.u.u.u. ; Scan recent deletions Miscellaneous . ; Repeat previous operation ~ ; Reverse case of letter and advance one position J ; Join lines together << ; Shift line left one tab position >> ; Shift line right one tab position :g/pattern/p ; Locate and print all occurrences of 'pattern' ; within the file. xp ; Reverse order of two letters dwwP ; Reverse order of two words ddp ; Reverse order of two lines