Basic Vim Tips
Normal mode
Insert mode
Command mode
Visual mode
Shell mode
A reference chart for Vim, primarily aimed at beginners. (Hi, Reddit.)
Help
-
Load help.
-
Get help on the 'j' command.
-
Get help on the ':split' command.
-
Get help for all commands that start with 'z'.
-
Go to the definition/tag under the cursor.
-
Go back one page in the help system.
-
Go forward one page in the help system.
Undo and redo
Movement: Lines
-
Jump to beginning of the current line.
-
Jump to first non-space character on the current line.
-
Jump to end of the current line.
-
Jump to the first line in the file.
-
Jump to the last line in the file.
-
Jump to line 47.
-
Jump to line 47 (alternate form).
Movement: Characters
-
Jump to next occurrence of [char].
-
Jump to third occurrence of [char].
-
Jump to previous occurrence of [char].
-
Jump to one character before the next occurrence of [char].
-
Jump to one character after the previous occurrence of [char].
-
Repeat last f/F/t/T movement.
-
Repeat last f/F/t/T movement in the opposite direction.
Movement: Words and text
-
Jump to beginning of next word.
-
Jump to beginning of next WORD (string of non-blank characters).
-
Jump to next end of word.
-
Jump to next end of WORD.
-
Jump back to beginning of previous word.
-
Jump back to beginning of previous WORD.
-
Jump back to beginning of previous sentence.
-
Jump to beginning of next sentence.
-
Jump back to beginning of previous paragraph.
-
Jump to beginning of next paragraph.
Movement: Code
-
Jump between opening/closing braces, brackets, parentheses, etc.
-
Jump to previous function.
-
Jump to next function.
-
Jump to beginning of current block.
-
Jump to end of current block.
Search
-
Search.
-
Search backwards.
-
Jump to next match.
-
Jump to next match, moving in the opposite direction.
-
Search for current word under the cursor.
-
Search for current word under the cursor, moving backwards.
Repetition
-
Repeat last command.
-
Delete 23 lines.
-
Jump down 5 lines.
-
Start recording keystrokes to the 'a' register.
-
Stop recording.
-
Execute the contents of the 'a' register (playing back the keystrokes—a macro, effectively).
-
Execute the contents of the 'a' register 4 times.
Replace
-
Replace all instances of 'search' with 'replace' throughout the whole file.
-
Replace all instances of 'search' with 'replace' from line 5 to line 10.
-
Find all [number]-[number] text and replace with [number]–[number]
-
Same as last, but using magic regex.
-
On lines that match the regex /foo/, replace 'bar' with 'BAR'.
-
Find lines that start with '<h5' in all HTML files in the current directory. Matches show up in the quickfix list.
-
Move to next entry in the quickfix list.
-
Move to previous entry in the quickfix list.
Insert mode
-
Go into insert mode before the character under the cursor.
-
Jump to beginning of the current line and enter insert mode.
-
Go into insert mode after the character under the cursor.
-
Jump to end of the current line and enter insert mode.
-
Add a blank line after current line and enter insert mode on that line.
-
Add a blank line before current line and enter insert mode on that line.
Deleting text
-
Delete the character under the cursor.
-
Delete from the cursor to the beginning of the next word.
-
Delete the current line.
-
Delete from cursor position to the end of the current line.
-
Delete from cursor position to [char]. (Also works with f.)
-
Delete from cursor position to the beginning of the next sentence.
-
Delete from cursor position to the end of the paragraph.
-
Delete inside parentheses. (You can be anywhere inside them.)
-
Delete around angle brackets.
-
Delete inside tag. (Meaning, delete what's between the opening and closing tags.)
Changing text
-
Join line (pull the next line up after the end of the current line).
-
Toggle the case (upper/lower) of the character under the cursor.
-
In visual mode: change selected text to lowercase.
-
In visual mode: change selected text to uppercase.
-
Replace character under cursor with [char].
-
Enter overtype mode.
-
Change from the cursor to the beginning of the next word (delete to that point and enter insert mode).
-
Change from cursor position to the beginning of the next sentence.
-
Change from cursor position to the end of the paragraph.
-
Change inside quotes (not including quotes).
-
Change around quotes (including quotes).
-
Change inside tag contents (between opening and closing tags).
-
Change a tag's contents (includes opening/closing tags).
-
Change inside sentence (doesn’t include space after period).
-
Change a sentence (includes space after period).
-
Change inside paragraph (doesn’t include blank line).
-
Change a paragraph (includes blank line).
-
Change inside tag name (between opening and closing angle brackets).
-
Change a tag name (includes brackets).
-
Change inside parentheses.
-
Change inside curly braces.
-
Change inside square brackets.
-
Delete the rest of the line and enter insert mode.
-
Change from cursor position to [char].
Indenting text
-
Indent current line.
-
Dedent current line.
-
In visual mode: Indent selected lines.
-
In visual mode: Dedent selected lines.
-
Indent current block (defined by curly braces).
-
Indent current paragraph.
-
Indent inside current set of curly braces.
-
In visual mode: Reformat selected text.
Selecting text and cut/copy/paste
-
Enter visual select (by character).
-
Enter visual select (by line).
-
Enter visual select (by column).
-
Re-select last selected area.
-
In visual mode: Yank (copy) selected text to the unnamed register (the clipboard).
-
In visual mode: Yank selected text to system clipboard.
-
Yank current line.
-
Yank from the cursor to the beginning of the next word.
-
Yank inside paragraph.
-
Yank a sentence.
-
Yank inside angle brackets.
-
Put (paste) text from the unnamed register.
-
Put text from the unnamed register before the cursor.
-
In insert mode: Put from the unnamed register.
-
Yank current line to the 'a' register. (:help registers for a list of registers.)
-
Put from the 'a' register.
Files and directories
-
Reload current file, abandoning any changes.
-
Insert the contents of [file].
-
Insert the results from the Unix date
command.
-
Echo current working directory to status line.
-
Change current working directory to [dir].
Buffers
Windows
-
Split window (one window on top of the other).
-
Split window (one window next to the other).
-
Split window and open [file] in the new window.
-
Close current window.
-
Close every window except for the current one.
-
Move focus to the window to the left.
-
Move focus to the window underneath.
-
Move focus to the window above.
-
Move focus to the window to the right.
-
Move focus to the window below/right of the current one.
-
Move focus to the window above/left of the current one.
Tabs
Scrolling
-
Jump to the high part of the screen.
-
Jump to the middle part of the screen.
-
Jump to the low part of the screen.
-
Scroll so the current line is at the top of the screen.
-
Scroll so the current line is in the middle of the screen.
-
Scroll so the current line is at the bottom of the screen.
Folding
-
In visual mode: Fold selected lines.
-
Fold 3 lines.
-
Open current fold under the cursor.
-
Close current fold under the cursor.
-
Toggle current fold under the cursor.
-
Open all folds.
-
Close all folds.
-
Delete fold under the cursor. (Leaves text intact, just removes fold.)
Autocompletion
-
Autocomplete current word. Also moves forward through autocomplete list.
-
Move backward through autocomplete list.
-
Omnicomplete. See :help omnifunc
Bookmarks and history
-
Set current position as mark 'a' (any lowercase letter will do).
-
Jump to mark 'a'. (The first character is a backtick, left of the '1' on your keyboard.)
-
Go back to the last place you edited. (You can do it multiple times in a row.)
Mapping keys
-
List all mapped keys.
-
List all mapped keys for insert mode.
-
List all mapped keys for normal mode.
-
Map 'jj' in insert mode to do the same as the escape key.
-
Map ',c' to indent the current line.
Useful options
-
Turn on syntax highlighting.
-
Turn on line numbers.
-
Wraps lines. (:set nowrap
turns it off.)
-
Show matches as you search rather than waiting for you to hit Enter.
-
When searching, ignore case unless you type a capital, in which case it’ll match case (smartcase).
-
Sets paste toggle to the F5 key, so you can paste text without the indentation going berserk.
-
Add an abbreviation, so when you type 'teh', it changes it to 'the'.
-
Another type of abbreviation, to save keystrokes (like TextExpander).
Miscellaneous
-
Sort selected text.
-
Sort the whole file.
-
Sort the first ten lines of the file.
-
Sort selected text using the external Unix sort
command with the -n
option.
-
Run the whole file through the external uniq
command.
-
Diff [file1] and [file2] using synchronized split windows.
-
In vimdiff mode, move to next line with differences.
-
In vimdiff mode, move to previous line with differences.
-
Open [file] in Vim and jump to the end of the file.
-
Open [file] in Vim and jump to line 21.
-
Show (in the status line) the first line containing the word under the cursor.
-
Show (in the status line) all lines containing the word under the cursor.
-
Show (in the status line) all lines that match the regex /pattern/
.
-
Open a remote file over SSH.
-
When you open or create a .php file, set the filetype to include HTML, JS, and CSS (for good syntax highlighting).
-
Make it so typing 'dts' followed by a space will insert the current date.
Cool plugins
-
An autoinstaller for Vim plugins. Indispensable.
-
Enables snippets (fast entry for boilerplate text).
-
A buffer explorer.
-
A fuzzy file/buffer finder.
-
A better status line.
-
Adds extra commands for working with quotes, parentheses, brackets, and more.
Sample .vimrc files
More reading