This section is a quick reference of many common vi commands. Some of these were discussed earlier in the chapter, while many will be new.
Table 15-1. Movement
Operation | Key |
---|---|
left, down, up, right | h, j, k, l |
To the end of the line | $ |
To the beginning of the line | ^ |
To the end of the file | G |
To the beginning of the file | :1 |
To line 47 | :47 |
Table 15-2. Editing
Operation | Key |
---|---|
Removing a line | dd |
Removing five lines | 5dd |
Replacing a character | r |
Removing a character | x |
Removing ten characters | 10x |
Undo last action | u |
Join current and next lines | J |
Table 15-3. Searching
Operation | Key |
---|---|
Search for “asdf” | /asdf |
Search backwards for “asdf” | ?asdf |
Repeat last search forwards | / |
Repeat last search backwards | ? |
Table 15-4. Saving and Quitting
Operation | Key |
---|---|
Quit | :q |
Quit without saving | :q! |
Write and quit | :wq |
Write, without quitting | :w |
Reload currently open file | :e! |
Write buffer to file asdf | :w asdf |
Open file hejaz | :e hejaz |
Read file asdf into buffer | :r asdf |
Read output of ls into buffer | :r !ls |