The One and Only - Original
CV'ers
VI Reference Page
"But Miss Lucey, I can't edit my quota - I don't know
vi..."
Cursor movement keys and commands
| h | one character to the left |
|---|---|
| l | one character to the right |
| k | up one line |
| j | down one line |
| <line_num>G | moves to the line number specified |
| G | moves to the end of a file |
Text insertion commands
| a | appends text after cursor |
|---|---|
| A | appends text at end of line |
| i | inserts text before cursor |
| I | inserts text at start of line |
| o | opens a line below cursor |
| O | opens a line above cursor |
Commands to eliminate text
| x | deletes character at cursor |
|---|---|
| dw | deletes word |
| dd | deletes line at cursor |
| D | deletes from cursor to end of line |
Commands to modify existing text
| r | replaces single character |
|---|---|
| R | replaces multiple characters |
| cw | change word at cursor |
| yw | copies (yanks) word |
| yy | copies (yanks) line |
| p | put copied input after cursor |
| P | put copied input before cursor |
| u | undo last change |
| U | undo all line changes |
| /string | locate string |
| n | locate next occurance of string |
| N | reverse search for string |
| :%s/string1/string2/ | substitute string1 for string2 |
| g | add to end of substitute for global substitute |
Commands to leave the vi session
| :w | writes (saves) the file |
|---|---|
| :w! | forces a write (save) |
| :q | quits a file (no save) |
| :q! | forces a quit |
| :wq | write and quit vi |
| ZZ | writes file if changes made or else just quit |
Additional cursor movement
| space | moves one char to the right |
|---|---|
| backspace | moves one char to the left |
| linefeed | down one line |
| - | up one line |
| + | down one line |
| CTRL-H | one character to the left |
| CTRL-J | down one line |
| CTRL-N | move down one line |
| CTRL-K | up one line |
| CTRL-P | move up one line |
| CTRL-D | scroll down half a screen |
| CTRL-U | scroll up half a screen |
| CTRL-F | scroll forward one page |
| CTRL-B | scroll backward one page |
| CTRL-Y | expose one more line at top of screen |
| CTRL-E | expose one more line at bottom of screen |
| w | moves you forward to the beginning of the next word |
| e | moves you forward to the end of the word |
| b | moves you backward to the beginning of the word |
| W | moves forward to the next character following a space |
| E | move to end of current big word |
| B | move to the beginning of the current big word |
| ) | forward to the beginning of the next sentence |
| ( | backward to the beginning of the sentence |
| { | forward to the beginning of the next paragraph |
| } | backward to the beginning of the paragraph |
| ]] | forward to the beginning of the next section |
| [[ | backward to beginning of the section |
| ^ | forward to the first nonblank character of the line |
| 0 | forward to the real beginning of the line |
| $ | forward to the end of the line |
| H | move to the home position, upper leftmost of your screen |
| M | move to the beginning of the middle line on your screen |
| L | move to the beginning of the last line on your screen |
| G | move to the end of the file |
| #G | move to that # line |
| #| | move to that # specified column |
| J | join two lines |
| . | repeats last command that changed the file |
6 Deletion
| d space | same as x (requires a space after d) |
|---|---|
| #d space | deletes # of characters (requires a space after d) |
| db | delete to the beginning of the word |
| de | delete to the end of the word |
| d0 | delete to the beginning of the line (from cursor position) |
| d) | delete to the end of the sentence |
| d{ | delete from start of current paragraph upto cursor position |
Replacing text
| #rx | replaces # amount of char with the letter x |
|---|---|
| r CR | replaces a character with a carraige return |
| c space | deletes single character, then insert mode (needs a space.) Use ESC. |
| #c space | deletes # characters, then insert mode (nees a space.) Use ESC. |
| cc | change the entire line. Use ESC to stop input. |
| C | same as cc |
While in text entry mode, certain key combinations are also available.
| CTRL-I | same as the tab key. Tabstops can be setup with the :se command |
|---|---|
| CTRL-W | backs up to the beginning of the current word when in entry mode |
| CTRL-U | backs up to the beginning of the current line when in entry mode |
| CTRL-D | back up over one level of indentation if autoindent set |
| 0CTRL-D | kill autoindent |
| ^CTRL-D | kill autoindent on this line, restore it on the next |
| CTRL-T | if in autoindent mode, insert one shiftwidth blank or tab |
Hitting ESC at any time, deletes all text starting with the cursor position forward to the end of the line.
Additional Keys
| ESC | terminate text entry/modification mode |
|---|---|
| . | repeat last change command |
| : | prepare to issue an ex command |
| ; | move to next occurence of symbol searched for with f or F on current line. |
| /pat | search for string pat, starting at cursor position |
| n | next occurence of pattern match |
| N | previous occurence of pattern match |
| ?pat | search for string pat, backwards from cursor position |
| J | join next line to current one |
| p | put contents of buffer into line below cursor |
| P | put contents of buffer into line above cursor |
| ~ | change case of character if alphabetic |
| CTRL-L | redraw screen, useful if scrambled |
| CTRL-R | redraw screen, eliminating deleted lines marked by @ |
| % | if given with cursor on (, {, [, moves it to matching |
| < | decrease indent of each level of object by one shiftwidth |
| > | increase indent of each level of object by one shiftwidth |
| = | reindent lisp program, as if it had been entered using lisp |
| z | redraw screen around current line |
Setting options
| :se | displays currently set options |
|---|---|
| :se all | displays all available options |
| :se autoindent | set autoindention feature. Structured tabs will be repeated line after line. Excelent for showing loops in programs |
| :se autowrite | automatically write out buffer (if changed) before :n, :rew, :stop, :ta, or :! given in visual mode |
| :se beautify | prevents entry of control characters |
| :se lisp | autoindent indents appropiately for lisp, and (), {}, [], commands suitably redefined |
| :se mesg | allow messages to be received while in vi |
| :se optimize | abolishes automatic CR when terminal prints |
| :se paragraphs=xxxx | specifies paragraph macros used by { and } commands |
| :se redraw | simulate intelligent terminal on dumb one |
| :se scroll=n | set scrolling paramter to n lines |
| :se sections=xxxx | specifies section macros used by [[ and ]] commands |
| :se shiftwidth=n | number of characters to be backspaces over by CTRL-D when autoindent is on |
| :se showmatch | when ) or } is entered, move cursor for one second to matching ( or { - verifies matching syntax |
| :se slowopen | delays updating of screen during insertions |
| :se tabstop=n | set editor tabs every n characters |
| :se taglength=x | (tl, tl=o) only first x characters of tag are significant |
| :se tags= path of files | path of files to be searched for tags |
| :se w300=n | set window size to n lines if speed is 300 baud |
| :se window=n | set window size to n lines |
| :se wrapmargin=n | set margin for word wraparound a n char from end of line |
| :se writeany | allow user to write to any file available to user |
NOTE: The vi editor keeps a copy of your file in the /tmp directory. In case of a system crash (or a killed shell), a mail file is created instructing the operator of the recoverable vi file. The normal procedure is to invoke the vi e ditor with the -r (recover) option. The file is usually recoverable up to your last carraige return.
Many thanks to setwei for typing this up!!!!