| See Also: vi Commands |
| vi [filename] | Opens named file in command mode |
| Insert Commands |
| i, a, I, A | Changes to insert mode and puts cursor before cursor, after cursor, at beginning of line, at end of line |
| cw | Change word (hit ESC when done editing) |
| cc | Change line |
| C | Change text up to end of line |
| r x | Replace character with x |
| R text | Replace text beginning at cursor |
| s | Substitute character |
| S | Substitue entire line |
| u | Undo insert |
| ESC | Go back to Command Mode |
| Cursor Movement Commands |
| CTRL-F, CTRL-B | Scroll forward, backward one screen |
| CTRL-D, CTRL-U | Scroll down, up half a screen |
| CTRL-L | Refresh (redraw) screen |
| :n | Moves to line number n |
| CTRL-G | Displays current line number of cursor |
| l, spacebar | Move one character forward (right) |
| h | Move one character backward (left) |
| k | Move to previous line (up) |
| j | Move to next line (down) |
| nG, :n | Move to line number n |
| G | Move to las line in file |
| ^G | Display current line number |
| w | Move one word forward |
| b | Move one word backward |
| e | Move to end of word |
| ( | Move to beginning of current sentence |
| ) | Move to beginning of next sentence |
| { | Move to beginning of current paragraph |
| } | Move to beginning of next paragraph |
| [[ | Move to beginning of current section |
| ]] | Move to beginning of next section |
| 0 | Move to beg of current line |
| $ | Move to end of current line |
| +, return | Move to beginning of next line |
| - | Move to beginning of previous line |
| n| | Column n of current line |
| H | Move to top line of screen |
| M | Move to middle line of screen |
| L | Move to bottom line of screen |
| nH | Move to n lines after top line |
| nL | Move to n lines before last line |
| ^F | Scroll forward |
| ^B | Scroll backward |
| Deletion Commands |
| x | Delete forward one character |
| X | Delete backward one character |
| 5X | Delete backward five characters |
| dd | Delete current line |
| ndd | Delete n number of lines |
| D | Delete remainder of line |
| dw | Delete word |
| d} | Delete up to next paragraph |
| d^ | Delete to beginning of line |
| d/ pattern | Delete until pattern |
| dn | Repeat d/pattern |
| df a | Delete until a on current line |
| dt a | Delete until a on current line butnot including a |
| dL | Delete up to last line on screen |
| dG | Delete up to end of file |
| p | Insert last deleted text after cursor |
| P | Insert last deleted text before cursor |
| u | Undo last change |
| U | Restore current line |
| . | Repeat last change |
| ~ | Reverse case |
| Copy and Paste Commands |
| y | Copy current line to new buffer |
| yy,Y; nyy,nY | Copy current line; Copy n lines |
| yw; nyw | Copy 1 word; Copy n words |
| y/pat | Copy until pattern |
| yn | Repeat y/pat |
| y} | Copy up to next paragraph |
| y^ | Copy up to beginning of line |
| yfa | Copy up to a on current line including a |
| yta | Copy up to a on current line excluding a |
| yl | Copy up to last line on screen |
| yG | Copy up to end of file |
| p | Paste after cursor. If line copied, paste below cursor |
| P | Paste before cursor. If line copied paste above cursor |
| Searching and Marking Commands |
| /text | Search forward for text |
| ?text | Search backward for text |
| n | Repeat previous search |
| N | Repeat search in opposite direction |
| / | Repeat forward search |
| ? | Repeat backward search |
| % | Find match of current parenthesis, brace or bracket |
| mx | Mark current position with character x |
| `x | Move cursor to mark x |
| 'x | Move to start of line containing x |
| `` | Return to previous mark |
| '' | Move to start of line containing previous mark |
| Saving and Exiting Commands |
| zz | Save and quit vi |
| :x | Save and quit vi |
| :wq | Save and quit vi |
| :w | Save file |
| :w file | Save to file |
| :n1,n2wfile | Save lines n1 to n2 to new file |
| :n1,n2w >> file | Save lines n1 to n2 to existing file |
| :w! | Save to file (overriding protection) |
| :w! file | Overwrite file |
| :w %.new | Save file as file.new |
| :q | Quit vi |
| :q! | Quit vi discarding edits |
| Q | Quit vi and invoke ex |
| :vi | Return to vi after Q command |
| :e file2 | Edit file2 without leaving vi |
| :n | Edit next file |
| :e! | Return to version of current file at time of last write |
| :e# | Edit alternate file |
| % | Current filename |
| # | Alternate filename |
| Accessing Multiple Files |
| :e file | Edit another file, current file becomes alternate |
| :e! | Restore last saved version of current file |
| :e + file | Edit at the end of file |
| :e+ n file | Edit file at line n |
| :e # | Opens to previous position in alternate file |
| :n | Edit next file |
| :n! | Force next file |
| :n files | Specify new list of files |
| ^G | Display current file and line number |
| :args | Display multiple files to be edited |
| :rew | Rewind list of multiple files to top |
| Other Commands |
| :sh | Create a subshell; Type exit to go back to vi |
| :!cmd | Run UNIX cmd then return to vi |
| !! | Repeat last system command |
| :so file | Read and execute command from file |
| :r !cmd | Read in output from file after current line |
| :r file | Read in contents of file after cursor |
| J | Join two lines |
| :j! | Join two lines, preserving blank spaces |
| << | Left shift line |
| >> | Right shift line |
| >} | Shift right to end of paragraph |
| <% | Shift left unitl matching parenthesis, brace or bracket |