This summary of vim includes all the commands covered in this chapter, plus a few more. Table 6-12 lists some of the ways you can call vim from the command line.
Table 6-12. Calling vim
Edits filename starting at line 1
vim +n filename
Edits filename starting at line n
vim + filename
Edits filename starting at the last line
vim +/pattern filename
Edits filename starting at the first line containing pattern
vim r filename
Recovers filename after a system crash
vim R filename
Edits filename readonly (same as opening the file with view)
You must be in Command mode to use commands that move the cursor by Units of Measure (Table 6-13). You can use these Units of Measure with Change, Delete, and Yank commands. Each of these commands can be preceded by a Repeat Factor.
Table 6-13. Moving the cursor by Units of Measure
Moves the cursor
SPACE, l (ell), or
Space to the right
h or LEFT ARROW
Space to the left
Word to the right
Blank-delimited word to the right
Word to the left
Blank-delimited word to the left
End of line
End of word to the right
End of blank-delimited word to the right
Beginning of line (cannot be used with a Repeat Factor)
Beginning of next line
j or DOWN ARROW
Down one line
Beginning of previous line
k or UP ARROW
Up one line
End of sentence
Beginning of sentence
End of paragraph
Beginning of paragraph
Move to matching brace of same type at same nesting level
Table 6-14 shows the commands that enable you to view different parts of the Work buffer.
Table 6-14. Viewing the Work buffer
Moves the cursor
Forward one-half window
Backward one-half window
CONTROL-F or PAGE DOWN
Forward one window
CONTROL-B or PAGE UP
Backward one window
To line n (without n, to the last line)
To top of window
To middle of window
To bottom of window
The commands in Table 6-15 enable you to add text to the buffer. All these commands, except r, leave vim in Input mode. You must press ESCAPE to return to Command mode.
Table 6-15. Adding text
Before first nonblank character on line
At end of line
Open a line below current line
Open a line above current line
Replace current character (no ESCAPE needed)
Replace characters, starting with current character (overwrite until ESCAPE)
Table 6-16 lists commands that delete and change text. In this table M is a Unit of Measure that you can precede with a Repeat Factor, n is an optional Repeat Factor, and c is any character.
Table 6-16. Deleting and changing text
Deletes the number of characters specified by n, starting with the current character
Deletes n characters before the current character, starting with the character preceding the current character
Deletes text specified by M
Deletes n lines
Deletes to the next character c on the current line
Deletes to end of the line
Change case of the next n characters
The following commands leave vim in Input mode. You must press ESCAPE to return to Command mode.
Substitutes n characters
Substitutes for the entire line
Changes text specified by M
Changes n lines
Changes to the next character c on the current line
Changes to end of line
Table 6-17 lists search commands. Here rexp is a regular expression that can be a simple string of characters.
Table 6-17. Searching
Searches forward for rexp
Searches backward for rexp
Repeats original search exactly
Repeats original search, in the opposite direction
Repeats original search forward
Repeats original search backward
Positions the cursor on the next character c on the current line
Positions the cursor on the previous character c on the current line
Positions the cursor on the character before (to the left of) the next character c on the current line
Positions the cursor on the character after (to the right of) the previous character c on the current line
Repeats the last f, F, t, or T command
The format of a Substitute command is
where address is one line number or two line numbers separated by a comma. A . (period) represents the current line, $ represents the last line, and % represents the entire file. You can use a marker or a search string in place of a line number. The search-string is a regular expression that can be a simple string of characters. The replacement-string is the replacement string. A g indicates a global replacement (more than one replacement per line).
Table 6-18 lists miscellaneous vim commands.
Table 6-18. Miscellaneous commands
Joins the current line and the following line
Repeats the most recent command that made a change
Writes contents of Work buffer to filename (or to current file if there is no filename)
Writes contents of Work buffer to the current file and quits vim
:f or CONTROL-G
Displays the filename, status, current line number, number of lines in the Work buffer, and percentage of the Work buffer preceding the current line
Inserts the next character literally even if it is a vim command (use in Input mode)
Table 6-19 lists commands that yank and put text. In this table M is a Unit of Measure that you can precede with a Repeat Factor and n is a Repeat Factor. You can precede any of these commands with the name of a buffer using the form "x, where x is the name of the buffer (a z).
Table 6-19. Yanking and putting text
Yanks text specified by M
Yanks n lines
Yanks to end of line
Puts text before or above
Puts text after or below
Table 6-20 lists advanced vim commands.
Table 6-20. Advanced commands
Sets marker x, where x is a letter from a to z.
''(two single quotation marks)
Moves cursor back to its previous location.
Moves cursor to line with marker x.
Moves cursor to character with marker x.
Edits filename, requiring you to write out changes to the current file (with :w or autowrite) before editing the new file. Use :e! filename to discard changes to the current file. Use :e! without a filename to discard changes to the current file and start editing the saved version of the current file.
Edits the next file when vim is started with multiple filename arguments. Requires you to write out changes to the current file (with :w or autowrite) before editing the next file. Use :n! to discard changes to the current file and edit the next file.
Rewinds the filename list when vim is started with multiple filename arguments and starts editing with the first file. Requires you to write out changes to the current file (with :w or autowrite) before editing the first file. Use :rew! to discard changes to the current file and edit the first file.
Starts a shell. Exit from the shell to return to vim.
Starts a shell and executes command.
Starts a shell, executes command, and places output in the Work buffer, replacing the current line.