Vim Commands Cheat Sheet

http://bullium.com/support/vim_print.html

Vim Commands Cheat Sheet
How to Exit Edit a File Inserting Text Deleteing Text Replacing Text Substituting Text Moving Text Undo/Redo/Repeat Moving Around (Cursor Motion) Marks Searching Selecting Text (Visual Mode) How to Suspend Vimtutor

How to Exit
:q[uit] :q[uit]! :cq[uit] :wq :wq! :wq {file} :wq! {file} :[range]wq[!] ZZ ZQ Quit Vim. This fails when changes have been made. Quit without writing. Quit always, without writing. Write the current file and exit. Write the current file and exit always. Write to {file}. Exit if not editing the last Write to {file} and exit always. [file] Same as above, but only write the lines in [range]. Write current file, if modified, and exit. Quit current file and exit (same as ":q!").

Editing a File
:e[dit] :e[dit]! :e[dit] {file} :e[dit]! {file} gf 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: "goto file".

1 of 7

02/07/2008 04:58 PM

~{motion} switch case of {motion} text. Insert text before the first non-blank in the line [count] times. Append text at the end of the line [count] times. repeat [count] times. When in Select mode: Delete the highlighted text Delete the highlighted lines Delete [range] lines (default: current line) Delete {count} lines. Begin a new line above the cursor and insert text. replacing characters rather than inserting Switch case of the character under the cursor and move the cursor to the ~ right. Deleting Text <Del> or x X d{motion} dd D {Visual}x or {Visual}d {Visual}CTRL-H or {Visual} {Visual}X or {Visual}D :[range]d[elete] :[range]d[elete] {count} Delete [count] characters under and after the cursor Delete Delete Delete Delete line [count] characters before the cursor text that {motion} moves over [count] lines the characters under the cursor until the end of the Delete the highlighted text (for {Visual} see Selecting Text). do that many characters. :r[ead] !{cmd} Execute {cmd} and insert its standard output below the cursor.Vim Commands Cheat Sheet http://bullium. starting with [range] Changing (or Replacing) Text r{char} R replace the character under the cursor with {char}.com/support/vim_print. Insert text in column 1 [count] times. Enter Insert mode. repeat [count] times. Inserting a file :r[ead] [name] Insert the file [name] below the cursor. Begin a new line below the cursor and insert text.html Inserting Text a A i I gI o O Append text after the cursor [count] times. {Visual}~ Switch case of highlighted text 2 of 7 02/07/2008 04:58 PM . If a [count] is given. Insert text before the cursor [count] times.

Yank [count] lines [into register x] yank [count] lines [into register x] (synonym for yy). Put the text [from register x] before the cursor [count] times.%#:} only work with put). Yank the highlighted lines [into register x] Yank [range] lines [into register x]. Yank the highlighted text [into register x] (for {Visual} see Selecting Text). yank or put (use uppercase character to append with delete and yank) ({. Display the contents of the numbered and named registers that are mentioned in {arg}. Yank {motion} text [into register x]. [p] Print the line containing the last substitute. [I] Don't ignore case for the pattern. [g] Replace all occurrences in the line. [i] Ignore case for the pattern.html Substituting :[range]s[ubstitute]/{pattern}/{string}/[c][e][g][p][r][i][I] [count] For each line in [range] replace a match of {pattern} with {string}. but leave the cursor just after the new text. in particular. 3 of 7 02/07/2008 04:58 PM . Put the text [from register x] after the cursor [count] times. Same as :registers. Display the contents of all numbered and named registers. [e] When the search pattern fails. Vim positions the cursor on the matching string.com/support/vim_print.Vim Commands Cheat Sheet http://bullium. Just like "p". do not issue an error message and. You can type: 'y' to substitute this match 'n' to skip this match to skip this match 'a' to substitute this and all remaining matches {not in Vi} 'q' to quit substituting {not in Vi} CTRL-E to scroll the screen up {not in Vi} CTRL-Y to scroll the screen down {not in Vi}.%#:-"} :reg[isters] :reg[isters] {arg} :di[splay] [arg] ["x]y{motion} ["x]yy ["x]Y {Visual}["x]y {Visual}["x]Y :[range]y[ank] [x] :[range]y[ank] [x] {count} ["x]p ["x]P ["x]gp Use register {a-zA-Z0-9. Yank {count} lines. You may add extra flags :[range]s[ubstitute] [c][e][g][r][i][I] [count] :[range]&[c][e][g][r][i][I] [count] The arguments that you can use for the substitute commands: [c] Confirm each substitution. continue in maps as if no error occurred. but without the same flags. replacement occurs only for the first occurrence in each line. [into register x]. Repeat last :substitute with same search pattern and substitute string. Without this argument.%#:-"} for next delete. starting with last line number in [range] (default: current line). Copying and Moving Text "{a-zA-Z0-9.

Undo/Redo/Repeat u :u[ndo] CTRL-R :red[o] U .html ["x]gP :[line]pu[t] [x] :[line]pu[t]! [x] Just like "P". Undo all latest changes on one line. To the first non-blank character of the line To the end of the line and [count . To the first character of the line (exclusive). Moving Around Basic motion commands: k h l j h or l or or k or or CTRL-P j or or CTRL-J or or CTRL-N 0 <Home> ^ $ or <End> g0 or g<Home> [count] characters to the left (exclusive). When lines don't wrap ('wrap' off): To the leftmost non-blank character of the current line that is on the screen. To the first character of the line (exclusive). but leave the cursor just after the new text.com/support/vim_print.Vim Commands Cheat Sheet http://bullium. Differs from "^" when the first non-blank character of the line is not on the screen. Redo [count] changes which were undone. Undo one change. Undo [count] changes. with count replaced with [count]. [count] characters to the right (exclusive). g^ 4 of 7 02/07/2008 04:58 PM . Put the text [from register x] after [line] (default current line). [count] lines upward [count] lines downward (linewise). Differs from "0" when a line is wider than the screen. Differs from "0" when the first character of the line is not on the screen.1] lines downward When lines wrap ('wrap on): To the first character of the screen line (exclusive). Redo one change which was undone. When lines wrap ('wrap' on): To the first non-blank character of the screen line (exclusive). When lines don't wrap ('wrap' off): To the leftmost character of the current line that is on the screen. Put the text [from register x] before [line] (default current line). Differs from "^" when a line is wider than the screen. {Vi: while not moved off of it} Repeat last change.

Till after [count]'th occurrence of {char} to the left.html g$ or g<End&gr. separated with white space. on the first non-blank character <underscore> (linewise). G <C-Home> or Goto line [count]. default last line. To the [count]'th occurrence of {char} to the left. Repeat latest f. f{char} F{char} t{char} T{char} . ). When lines wrap ('wrap' on): To the last character of the screen line and [count . The cursor is placed on {char} (inclusive). <CR> _ [count] . An empty line is also considered to be a word and a WORD. tabs. on the first non-blank character (linewise). t. Differs from "$" when a line is wider than the screen.Vim Commands Cheat Sheet http://bullium. A WORD consists of a sequence of non-blank characters. separated with white space (spaces.com/support/vim_print. on the first non-blank character. gg <S-Right> or [count] words forward w <C-Right> or [count] WORDS forward W e Forward to the end of word [count] E Forward to the end of WORD [count] <S-Left> or [count] words backward b <C-Left> or [count] WORDS backward B ge Backward to the end of word [count] gE Backward to the end of WORD [count] These commands move over words or WORDS. Repeat latest f.1 lines downward. t.<minus> + or CTRL-M or [count] lines downward. . The cursor is placed on the character right of {char} (inclusive). or a sequence of other non-blank characters. ( ) { } [count] [count] [count] [count] sentences backward sentences forward paragraphs backward paragraphs forward 5 of 7 02/07/2008 04:58 PM . To [count]'th occurrence of {char} to the right. on the first non-blank character (linewise). The cursor is placed on the character left of {char} (inclusive). This can be changed with the 'iskeyword' option. F or T [count] times. F or T in opposite direction [count] times.1] screen lines downward (inclusive). Differs from "$" when the last character of the line is not on the screen or when a count is used. digits and underscores. <C-End> or Goto line [count]. on the first non-blank character. A word consists of a sequence of letters. The cursor is placed on {char} (inclusive). . Till before [count]'th occurrence of {char} to the right. default first line. [count] lines upward. When lines don't wrap ('wrap' off): To the rightmost character of the current line that is visible on the screen.

To the first non-blank character on the line with mark {a-z} (linewise). this is not a motion command). ][ [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 m{a-zA-Z} m' or m` :[range]ma[rk] {a-zA-Z} :[range]k{a-zA-Z} '{a-z} '{A-Z0-9} `{a-z} `{A-Z0-9} :marks :marks {arg} Set mark {a-zA-Z} at cursor position (does not move the cursor. This can be jumped to with the "''" or "``" command (does not move the cursor.com/support/vim_print. then the '}' in the first column. 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). Repeat the latest "/" or "?" [count] times in opposite N direction.html [count] sections forward or to the next '{' in the first column. If {offset} is empty no offset is used.Vim Commands Cheat Sheet http://bullium. but the space before the mark name can be omitted. If {offset} is empty no offset is used. n Repeat the latest "/" or "?" [count] times. column 0. For example: Searching /{pattern}[/] Search forward for the [count]'th occurrence of {pattern} Search forward for the [count]'th occurrence of {pattern} /{pattern}/{offset} and go {offset} lines up or down. Search backward for the [count]'th previous occurrence of ?{pattern}[?]<CR> {pattern} backward for the [count]'th previous occurrence of ?{pattern}?{offset}<CR> Search {pattern} and go {offset} lines up or down ?<CR> Search backward for the [count]'th latest used pattern Search backward for the [count]'th latest used pattern ??{offset}<CR> with new {offset}. 6 of 7 02/07/2008 04:58 PM . /<CR> Search forward for the [count]'th latest used pattern Search forward for the [count]'th latest used pattern with //{offset}<CR> new. Set the previous context mark. Default is cursor line. Set mark {a-zA-Z} at last line number in [range]. Same as :mark. When used after an ]] operator. List the marks that are mentioned in {arg} (not a motion command). this is not a motion command).

If the '!' is not given and 'autowrite' is set. Then. use some command on the text. Vim. This is vimtutor Instead a built in tuturial for VIM.html Selecting Text (Visual Mode) To select text. The operators that can be used are: ~ switch case d delete c change y yank > shift right < shift left ! filter through external command = filter through 'equalprg' option command gq format lines to 'textwidth' length v V <Esc> start Visual mode per character. enter visual mode with one of the commands below. it is a very usfull and handy tool. NOTE: Ubuntu users need to install the "vim-full" package for vimtutor to work. In Insert and Command-line mode. 7 of 7 02/07/2008 04:58 PM . changed buffers are not written. don't forget to :st[op][!] bring Vim back to the foreground later! CTRL-Z Vimtutor of running vim from your shell try running vimtutor instead.com/support/vim_print. Works in Normal and in Visual mode. and use motion commands to highlight the text you are interested in. every buffer :sus[pend][!] Suspend with changes and a file name is written out.Vim Commands Cheat Sheet http://bullium. the CTRL-Z is inserted as a normal character. If the '!' is given or or 'autowrite' is not set. start Visual mode linewise. The Ubuntu default vim install uses the "vim-tiny" package which installs a basic vim installation to help conserve disk space. exit Visual mode without making any changes How to Suspend Suspend Vim. like ":stop".