Vi Unix Editor Ref
Vi Unix Editor Ref
Contents
Insert Commands Miscellaneous Commands Movement Commands Word/Line Screen Text Modification Commands Delete Change Text Yank and Put Commands Moving Text Copying Text Moving/Copying Text Between Files Saving, Quitting, and Colon Commands Search and Replace Commands Customization - Set Options ($HOME/.exrc)
The vi editor has several modes used to complete file editing tasks. The insert and append modes allow the user to type in changes. All other editor commands (such as deletions, cut and paste, etc) are done in the command mode. To enter command mode press the ESC key. Some commands will put you into one of the other modes, so before using a command mode sequence press ESC to assure you are in the correct mode. All commands are case sensitve, like UNIX. Many of the commands will operate multiple times when the command is preceeded with a number. Example, deleting a single line is dd and deleting 5 lines is 5dd.
Insert Commands
i a I A r R o O (Issue one of these commands, after hitting ESC, to begin typing or changing the text) insert mode - can begin typing right where the cursor is in the file. append mode insert at beginning of line append at end of line replace a single character overstrike mode open a line below the cursor - Insert mode will be turned on and the cursor moved down 1 line open a line above the cursor - Insert mode will be turned on and the cursor moved up 1 line
Miscellaneous Commands
ctrl-g ctrl-l J . u U ~ xp show status line, number of lines redraw screen join two lines together repeat the last command undo the last command restore line to original change the case of character transpose two characters
Movement Commands
Word/Line
h l j k w W b B e ^ $ #<return> go one space left go one space right go one line down go one line up go to next word go to next space go to start of word go to previous space go to end of word beginning of line end of line Down # lines
Screen
ctrl-d ctrl-u ctrl-f ctrl-b H M L 1G G xG mx `x go down half a screen go up half a screen go forward a screen go back a screen go to top of screen go to middle of screen go to bottom of screen go to top of file go to end of file go to line x mark this line by x go to line marked by x
Change
cc xcc cw cW cb cB C s S change the current line change x lines change to end of word change to the next space change to beginning of word change to previous space change to end of line substitute text for character substitute for entire line
Moving Text
1. 2. 3. First place the text to be moved into a buffer using dd, ndd, dw, x, or nx (i.e. any delete operation). Move the cursor to the new location. Paste the text at the new location using p or P.
Copying Text
2. 3. First, place the text to be copied into a buffer using yy, nyy, yw, or nyw (i.e. any yank operation). Move the cursor to the new location. Paste the copy of the text at the new location using p or P. 1.