Mode | Command | Outcome |
---|---|---|
Any | <Escape> | Enter Command mode |
Command | i | Enter Insert mode |
Any | <Arrow Keys> | Move the cursor in the direction pointed by the arrow key |
Any | <Page Up/Down> | Move the cursor one page up or down |
Any | <Home/End> | Move the cursor to start or end of a line |
Command | w | Move forward one word |
Command | b | Move back one word |
Command | ) | Move forward one sentence |
Command | ( | Move back one sentence |
Command | } | Move forward one paragraph |
Command | { | Move back one paragraph |
Command | x[movement] | Move movement x times Ex. 15} moves us 15 paragraphs forward |
Command | c[movement] | “Change” - Deletes everything within the next movement away and enters insert mode Ex. c3w deletes the next 3 words and enters insert mode |
Command | d[movement] | Delete movement and add them to the buffer (described in section 5) Ex. d4) deletes 4 sentences |
Command | xd[movement] | Equivalent to dxmovement |
Command | u | Undo previous changes (i.e. move back through undo history) |
Command | <Ctrl>-r | Redo previously undone changes (i.e. move forward through undo history) |
Command | 0 | Equivalent to <Home> |
Command | $ | Equivalent to <End> |
Command | xx | Delete x characters and add them to the buffer (described in section 5) Ex. 5x deletes 5 characters |
Command | x~ | Changes the case of the next x letters, non-letters (whitespace, numbers, etc.) Ex. 15~ reverses the case of the next 15 letters |
Command | r[key] | Replace the character under the cursor with [key] |
Command | R | Enter Replace mode |
Command | <Insert> | Enter Insert mode |
Insert | <Insert> | Enter Replace mode |
Command | A | Append - Move cursor to end of current line and enter Insert mode |
Command | o | Open - Create a new line under the current line, move the cursor to it, and enter Insert mode |
Command | O | Open - Create a new line above the current line, move the cursor to it, and enter Insert mode |
Command | xdd | Delete x lines and place them in the buffer Similar to “cut” Ex. 5dd deletes the next 5 lines |
Command | xcc | Delete x lines and enter Insert mode Ex. 2cc deletes the next 2 lines and enters Insert mode |
Command | p | Place whatever is in the buffer (“clipboard”) after the cursor. If the buffer contains a line or more, place the contents of the buffer on the line following the current line. |
Command | P | Place whatever is in the buffer (“clipboard”) before the cursor. If the buffer contains a line or more, place the contents of the buffer on the line above the current line. |
Command | y[movement] | Yank movement (add it to the buffer) Similar to “copy” Ex. y4w yanks 4 words |
Command | xyy | Yanks x (places them in the buffer) Similar to “copy” Ex. 5yy yanks the next 5 lines |
Execute | :x | Jump to line x |
Execute | :w [filename] | Write (“save”) curent editing session to filename. If no filename is specified, write to the document associated with this session (the last file written to, opened from, etc.) |
Execute | :q | Quit the current editing session. ViM will not quit if you have not saved. |
Execute | :wq [filename] | Write (“save”) curent editing session to filename and then quit. If no filename is specified, write to the document associated with this session (the last file written to, opened from, etc.) |
Execute | :e [filename] | Edit - Open filename using the current editing window. This closes the current file. |
Execute | :[command]! [arguments] | Force - Perform the command regardless of any rammifications Ex. :q! Quits the session whether or not the file has been saved. |
Execute | :[command]a [arguments] | All - Perform the command to all open windows |
Execute | :split [filename] | Opens a new editing session in a new “window” to edit filename. If filename is blank, open the current document. |
Command | <Ctrl>-w <Ctrl>-w | Move cursor to next window (vertically) |
Execute | :help [keystroke] | Shows help for given keystroke in new window. If no topic is given, show generic help screen. |
Execute | :help :[command] | Shows help for given command in new window. If no topic is given, show generic help screen. |
Execute | :help [topic] | Shows help for given topic in new window. If no topic is given, show generic help screen. |
Command | /[searchTerm] | Searches forward for regular expressions that match searchTerm and places cursor on the next match |
Command | ?[searchTerm] | Searches backward for regular expressions that match searchTerm and places cursor on the next match |
Command | * | Searches forward for the word that is currently under the cursor |
Command | n | Place cursor on next match for the most recent search |
Command | N | Place cursor on previous match for the most recent search |
Execute | :set ignorecase | In all searches/regular expressions, be case insensitive |
Execute | :set noignorecase | In all searches/regular expressions, be case sensitive (Default) |
Execute | :s/oldWord/newWord/g | Replace all oldWords with the newWord on this line |
Execute | :%s/oldWord/newWord/g | Replace all oldWords with the newWord in this file |
Execute | :%s/oldWord/newWord/gc | Replace all oldWords with the newWord in this file, asking for confirmation on each entry |
Execute | :set option | Set the boolean option, option to true Ex. :set ignorecase |
Execute | :set nooption | Set the boolean option, option to false Ex. :set noignorecase |
Execute | :set option=[Value] | Set the option, option, to [Value] Ex. :set wm=5 |
Execute | :set ignorecase | Ignores case while searching |
Execute | :set mouse=[Value] | Allows the mouse to be an input in Value is “a”, or nothing if Value is “” Ex. :set mouse=a |
Execute | :set wm=[Value] | Set the word margin (the character position from the right at which point ViM wraps words) to Value Ex. :set wm=5 |
Execute | :set bg=[Value] | Tell ViM the terminal’s background color so that it may highlight appropriately Ex. :set bg=dark |
Execute | :set bs=[Value] | Tell ViM how to deal with backspaces. Value can be either a comma separated list or a numeric value (see help pages) Ex. :set backspace=2 |
Execute | :set ww=[Value] | Informs ViM which characters wrap around a newline. See the help pages for specifics Ex. :set ww=b,s,<,>,[,] |
Execute | :set autoindent | If this option is set, whenever you press [Enter] or open a new line, the indentation of the previous line is used for the new line |
Execute | :set sts=[Value] | Tabs will be treated as Value spaces Ex. :set sts=4 |
Execute | :set sw=[Value] | Shifts (“>>”) will be treated as Value spaces Ex. :set sw=4 |
Execute | :set expandtab | Expands each tab press into as ‘sts’ spaces Ex. :set noexpandtab |
Execute | :syntax [on/off] | Turns syntax highlighting on or off Ex. :syntax on |
Execute | :set syntax=[Value] | Tells ViM which syntax to highlight Ex. :set syntax=php |
Execute | :set number | Turns line numbering on |
Execute | :set smartindent | Tells ViM to use “smart indenting” which includes indenting after certain characters (like ‘{’). See help page for more |
Execute | :set cindent | Tells ViM to use “c indenting” which includes the indentation in ‘smartindent’ as well as after certain c keywords and structures. See the help page for more |
Cmd-Bang | :![Command] | Execute the external Command Ex. :!ls -a lists all files in the current directory |
Cmd-Bang | :!gcc progName.c -g -Wall | Uses the external gcc to compile progName.c Ex. :!gcc calc1.c -g -Wall |
Cmd-Bang | :!./progName | Runs the file, progName, which is in the current directory Ex. :!./a.out runs the output of gcc |
Cmd-Bang | % | Used as a placeholder for the current file’s name Ex. :!echo % prints the file name |
Command | x>> | Shift the next x lines ‘sw’ characters right |
Command | x<< | Shift the next x lines ‘sw’ characters left |
Command | % | Move to the matching paren/brace |
Command | zf[Movement] | Make a new fold of the next Movement lines Ex. zf} creates a fold of the next paragraph |
Command | zc | Closes the fold that the cursor is in |
Command | zo | Opens the fold that the cursor is on |
Insert | <Ctrl-v>[Key] | Insert the leteral Key character Ex. <Ctrl-v><Tab> inserts a tab character |