Exiting
|
Quit Vim This fails when changes have been made. |
|
Quit without writing |
|
Quit all buffers / tabs |
|
Quit always, without writing |
|
Write the current file and exit |
|
Quit and write all buffers / tabs |
|
Write the current file and exit always |
|
Write to {file}. Exit if not editing the last |
|
Write to {file} and exit always |
|
Write the lines in [range] and exit always |
|
Write current file, if modified, and exit |
|
Quit current file and exit Same as |
Editing a File
|
Edit the current file This is useful to re-edit the current file, when it has been changed outside of Vim. |
|
Edit the current file always Discard any changes to the current buffer. This is useful if you want to start all over again. |
|
Edit {file} |
|
Edit {file} always Discard any changes to the current buffer. |
|
Edit the file whose name is under or after the cursor Mnemonic: |
Inserting Text
|
Append text after the cursor [count] times |
|
Append text at the end of the line [count] times |
|
Insert text before the cursor [count] times |
|
Insert text before the first non-blank in the line [count] times |
|
Insert text in column 1 [count] times |
|
Begin a new line below the cursor and insert text, repeat [count] times |
|
Begin a new line above the cursor and insert text, repeat [count] times |
Inserting a File
|
Insert the file [name] below the cursor |
|
Execute {cmd} and insert its standard output below the cursor |
Deleting Text
|
Delete [count] characters under and after the cursor |
|
Delete [count] characters before the cursor |
|
Delete text that {motion} moves over |
|
Delete [count] lines |
|
Delete the characters under the cursor until the end of the line |
|
Delete the highlighted text For {Visual} see Selecting Text. |
|
Delete the highlighted text when in Select mode |
|
Delete the highlighted lines |
|
Delete [range] lines Default: current line. |
|
Delete {count} lines, starting with [range] |
Changing / Replacing Text
|
Replace the character under the cursor with {char} |
|
Enter Insert mode, replacing characters rather than inserting |
|
Switch case of the character under the cursor and move the cursor to the right If a [count] is given, do that many characters. |
|
Switch case of {motion} text |
|
Switch case of highlighted text |
|
Uppercase highlighted text |
|
Comment vertical selection Select range in column where comment char should appear with |
|
Uncomment vertical selection Select range in column where comment char should be removed with |
Information
|
Jump to matching brace |
|
Highlight all occurrences of word under cursor |
Ranges
A range permits a command to be applied to a group of lines in the current buffer. For most commands, the default range is the current line.
|
Substituting
For each line in [range] replace a match of {pattern} with {string} :[range]s[ubstitute]/{pattern}/{string}/[c][e][g][p][r][i][I] [count] |
|
Repeat last :substitute with same search pattern and substitute string, but without the same flags :[range]s[ubstitute] [c][e][g][r][i][I] [count] :[range]&[c][e][g][r][i][I] [count] You may add extra flags. |
|
The arguments that you can use for the substitute commands:
|
Copying and Moving Text
|
Use register {a-zA-Z0-9.%#:-"} for next delete, yank or put Use uppercase character to append with delete and yank. {.%#:} only work with put. |
|
Display the contents of all numbered and named registers |
|
Display the contents of the numbered and named registers that are mentioned in {arg} |
|
Yank {motion} text [into register x] |
|
Yank [count] lines [into register x] |
|
Yank the highlighted text [into register x] For {Visual} see Selecting Text. |
|
Yank the highlighted lines [into register x] |
|
Yank [range] lines [into register x] |
|
Yank {count} lines, starting with last line number in [range], [into register x] Default: current line. |
|
Put the text [from register x] after the cursor [count] times |
|
Put the text [from register x] before the cursor [count] times |
|
Just like |
|
Just like |
|
Put the text [from register x] after [line] Default: current line. |
|
Put the text [from register x] before [line] Default: current line. |
Undo, Redo and Repeat
|
Undo [count] changes |
|
Undo one change |
|
Redo [count] changes which were undone |
|
Redo one change which was undone |
|
Undo all latest changes on one line. |
|
Repeat last change, with count replaced with [count] |
Moving Around
Basic motion commands k <up> h l <left> <right> j <down> |
|
|
[count] characters to the left (exclusive) |
|
[count] characters to the right (exclusive) |
|
[count] lines upward |
|
[count] lines downward (linewise) |
|
To the first character of the line (exclusive) |
|
To the first non-blank character of the line |
|
To the end of the line and [count - 1] lines downward |
|
To the first character of the screen line (exclusive) when lines wrap ('wrap on). Differs from To the leftmost character of the current line that is on the screen when lines don't wrap ('wrap' off). Differs from |
|
To the first non-blank character of the screen line (exclusive) when lines wrap ('wrap' on). Differs from To the leftmost non-blank character of the current line that is on the screen when lines don't wrap ('wrap' off). Differs from |
|
To the last character of the screen line and [count - 1] screen lines downward (inclusive) when lines wrap ('wrap' on). Differs from To the rightmost character of the current line that is visible on the screen when lines don't wrap ('wrap' off). Differs from |
|
To [count]'th occurrence of {char} to the right. The cursor is placed on {char} (inclusive) |
|
To the [count]'th occurrence of {char} to the left. The cursor is placed on {char} (inclusive) |
|
Till before [count]'th occurrence of {char} to the right. The cursor is placed on the character left of {char} (inclusive) |
|
Till after [count]'th occurrence of {char} to the left. The cursor is placed on the character right of {char} (inclusive) |
|
Repeat latest f, t, F or T [count] times |
|
Repeat latest f, t, F or T in opposite direction [count] times |
|
[count] lines upward, on the first non-blank character (linewise) |
|
[count] lines downward, on the first non-blank character (linewise) |
|
[count] - 1 lines downward, on the first non-blank character (linewise) |
|
Goto line [count] on the first non-blank character Default: last line. |
|
Goto line [count] on the first non-blank character Default: first line. |
|
[count] words forward |
|
[count] WORDS forward |
|
Forward to the end of word [count] |
|
Forward to the end of WORD [count] |
|
[count] words backward |
|
[count] WORDS backward |
|
Backward to the end of word [count] |
|
Backward to the end of WORD [count] |
|
Move to the top of the screen |
|
Move to the middle of the screen |
|
Move to the bottom of the screen |
|
Scroll the line with the cursor to the center of the screen |
|
Scroll the line with the cursor to the top |
|
Scroll the line with the cursor to the bottom |
The following commands move over words or WORDS. A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, <EOL>). This can be changed with the 'iskeyword' option. A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a word and a WORD. |
|
|
[count] sentences backward |
|
[count] sentences forward |
|
[count] paragraphs backward |
|
[count] paragraphs forward |
|
[count] sections forward or to the next '{' in the first column When used after an operator, then the '}' in the first column. |
|
[count] sections forward or to the next '}' in the first column |
|
[count] sections backward or to the previous '{' in the first column |
|
[count] sections backward or to the previous '}' in the first column |
Marks
|
Set mark {a-zA-Z} at cursor position Does not move the cursor, this is not a motion command. |
|
Set the previous context mark This can be jumped to with the |
|
Set mark {a-zA-Z} at last line number in [range], column 0 Default is cursor line. |
|
To the first non-blank character on the line with mark {a-z} (linewise) |
|
To the first non-blank character on the line with mark {A-Z0-9} in the correct file |
|
To the mark {a-z} |
|
To the mark {A-Z0-9} in the correct file |
|
List all the current marks (not a motion command) |
|
List the marks that are mentioned in {arg} (not a motion command). For example: |
Searching
|
Search forward for the [count]'th occurrence of {pattern} |
|
Search forward for the [count]'th occurrence of {pattern} and go {offset} lines up or down |
|
Search forward for the [count]'th latest used pattern |
|
Search forward for the [count]'th latest used pattern with new If {offset} is empty no offset is used. |
|
Search backward for the [count]'th previous occurrence of {pattern} |
|
Search backward for the [count]'th previous occurrence of {pattern} and go {offset} lines up or down |
|
Search backward for the [count]'th latest used pattern |
|
Search backward for the [count]'th latest used pattern with new {offset} If {offset} is empty no offset is used. |
|
Repeat the latest |
|
Repeat the latest |
|
Search in files with internal grep Results are put into "quickfix list" open with
|
Selecting Text (Visual Mode)
To select text, enter visual mode with one of the commands below, and use motion commands to highlight the text you are interested in. Then, use some command on the text. The operators that can be used are:
|
|
|
Start Visual mode per character |
|
Start Visual mode linewise (horizontal selection) |
|
Start Visual mode columnwise (vertical selection) |
|
Exit Visual mode without making any changes |
|
Visually select inner word (where the cursor is positioned) |
Suspending
|
Suspend Vim Like |
|
Suspend Vim! If the '!' is not given and 'autowrite' is set, every buffer with changes and a file name is written out. If the '!' is given or 'autowrite' is not set, changed buffers are not written, don't forget to bring Vim back to the foreground later! |
Multiple Windows
|
Edit another file |
|
Split window and load another file |
|
Vertical split current window |
|
Horizontal split current window |
|
Move cursor up a window |
|
Move cursor to another window (cycle) |
|
Maximize current window |
|
Make all equal size |
|
Increase window size by 10 lines |
|
Vertical split |
|
Same as split, but readonly |
|
Close current window |
|
Keep only this window open |
|
Show current buffers |
|
Open buffer #2 in this window |
|
Close current buffer If |
Browsing with Tags
When editing programs, there is often a need to jump to another location. Vim uses a tags file that lists each word and location. The tags file has to be created by a utility able to handle the syntax of your files, and has to be updated after significant editing has occurred. |
|
|
Jump to tag Postion the cursor over a tag name, visually select text, use the left-mouse-button (LMB). Pushes current location to tag stack for later return. |
|
Return after jump Pops location to jump to from tag stack. |
|
Show tag stack List of return locations, used by |
Internal Lists
|
|
|
Open "quickfix list" (one global list) |
|
Close "quickfix list" |
|
Open "location list" (one per window) |
Notes
- Based on the cheat sheet from fprintf.
- Converted by Arief Bayu Purwanto.