| i |
enter edit mode |
| :w |
save file ("write" command) |
| :w fileName |
saves to the file called "fileName" |
| :q |
closes vi ("quit" command) |
| :q! |
closes vi without saving changes to file |
| :r fileName |
opens file fileName ("read" command) |
| u |
undo last edit |
| dl |
delete one letter |
| dw |
delete one word |
| dd |
delete one line |
| 8dd |
delete 8 lines |
| yy |
copy one line |
| p |
paste |
| /text |
searches for first example of "text" in file |
| n |
searches for next example of "text" in file |
| ^ |
place cursor at front of line |
| $ |
place cursor at end of line |
| G |
place cursor at end of document |
| 1G |
place cursor at beginning of document |
| :s/text1/text2/ |
replace first example of "text1" in current line with "text2" |
| :bn |
Switch between files — if you have opened
multiple files in vi, you view one at a time and switch between them
using :bn |