vi Text Editor
vi (visual) is a display orientated interactive text editor. Using vi you may edit an old file or
you may create a new file. The user may enter new text, delete text, delete lines of text, open new
lines of text, and replace old text with new text.
Type: vi filename
The screen should clear and the text from your file should appear on the screen. The vi editor does not
work directly with your file, instead it operates on a copy of your file. So you may make as many changes
as you want and not affect your original file if you do not save your file when you exit vi. Note that Unix
does not keep different versions of a file.
| :w | write buffer |
| :q | quit |
| :wq | save file and exit vi |
| :q! | abandon buffer (quit and don't save) |
| ZZ | same as :wq save file and exit vi |
| ctrl Z | suspend vi |
You will use the arrow keys on your keyboard to move your cursor around on the screen. If for
some reason the arrow keys do not work on your terminal you may also use the following keystrokes to navigate.
| k | line up |
| j | line down |
| l | right space |
| h | left space |
| ctrl D | scroll down |
| w | word forward |
| b | word backward |
| e | end of word |
| 0 (zero) | beginning of line |
| $ | end of current line |
| G | end of file |
| ctrl-B | page backwards one page |
| ctrl-F | page forward in the file |
| line number and press G | go to a specific line number |
(To exit insert mode press esc.)
| a | after cursor |
| A | at end of line |
| i | before cursor |
| I | at beginning of line |
| o | open line below |
| O | open line above |
| yw | yank word (copy word - press p to paste the word elsewhere) |
| yy or Y | yank line (copy line - press p to paste the word elsewhere) |
| p | put |
| cw | word |
| cc or S | line |
| C | rest of line |
| s | under cursor |
| r | replace character |
| dw | word |
| dd | line |
| D | rest of line |
| x | under cursor |
| X | before cursor |
| xp | transpose |
| u | undo change |
| . | repeat |
| /word | find down (word is the word you are trying to find) |
| ? | find up |
| n | next |
| ctrl-L | refresh the screen |
|