16.7 Vi Keys

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 16-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 16-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
Replace old with new, globally %s'old'new'g

Table 16-3. Searching

Operation Key
Search for “asdf” /asdf
Search backwards for “asdf” ?asdf
Repeat last search forwards /
Repeat last search backwards ?
Repeat last search, same direction n
Repeat last search, opposite direction N

Table 16-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