A Great Vim Cheat Sheet
A Great Vim Cheat Sheet
Note: If you’re decent at Vim and want your mind blown, check out Advanced Vim.
I’ve compiled a list of essential Vim commands that I use every day. I have then given a few instructions on how
to make Vim as great as it should be, because it’s painful without configuration.
Insert/Appending/Editing Text
Results in Insert mode
i - start insert mode at cursor
I - insert at the beginning of the line
a - append after the cursor
A - append at the end of the line
o - open (append) blank line below current line (no need to press return)
O - open blank line above current line
cc - change (replace) an entire line
c [movement command] - change (replace) from the cursor to the move-to point.
ex. ce changes from the cursor to the end of the cursor word
Esc or Ctrl+[ - exit insert mode
r [char] - replace a single character with the specified char (does not use Insert mode)
d - delete
d - [movement command] deletes from the cursor to the move-to point.
ex. de deletes from the cursor to the end of the current word
dd - delete the current line
Advanced
J - join line below to the current one
Visual commands
Type any of these while some text is selected to apply the action
Exiting
:w - write (save) the file, but don’t exit
:wq - write (save) and quit
:q - quit (fails if anything has changed)
:q! - quit and throw away changes
Search/Replace
/pattern - search for pattern
?pattern - search backward for pattern
n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new throughout file (gn is better though)
:%s/old/new/gc - replace all old with new throughout file with confirmations
Marks
Marks allow you to jump to designated points in your code.
General
u - undo
Ctrl+r - redo
. - repeat last command
.vimrc
My .vimrc file has some pretty great ideas I haven’t seen elsewhere.
This is a minimal vimrc that focuses on three priorities:
adding options that are strictly better (like more information showing in autocomplete)
more convenient keystrokes (like [space]w for write, instead of :w [enter] )
a similar workflow to normal text editors (like enabling the mouse)
Installation
Copy this to your home directory and restart Vim. Read through it to see what you can now do (like
[space]w to save a file)
Mac users - making a hidden normal file is suprisingly tricky. Here’s one way:
in the command line, go to the home directory
type nano .vimrc
paste in the contents of the .vimrc file
ctrl+x , y , [enter] to save
You should now be able to press [space]w in normal mode to save a file.
[space]p should paste from the system clipboard (outside of Vim).
If you can’t paste, it’s probably because Vim was not built with the system clipboard option. To check,
run vim --version and see if +clipboard exists. If it says -clipboard , you will not be able to
copy from outside of Vim.
For Mac users, homebrew install Vim with the clipboard option. Install homebrew and then run brew
install vim .
then move the old Vim binary: $ mv /usr/bin/vim /usr/bin/vimold
restart your terminal and you should see vim --version now with +clipboard
Plugins
The easiest way to make Vim more powerful is to use Vintageous in Sublime Text (version 3). This gives
you Vim mode inside Sublime. I suggest this (or a similar setup with the Atom editor) if you aren’t a Vim
master. Check out Advanced Vim if you are.
Vintageous is great, but I suggest you change a few settings to make it better.
Clone this repository to ~/.config/sublime-text-3/Packages/Vintageous , or similar. Then check
out the “custom” branch.
Alternatively, you can get a more updated Vintageous version by cloning the official repository
and then copying over this patch.
Change the user settings ( User/Preferences.sublime-settings ) to include:
"caret_style": "solid"
This will make the cursor not blink, like in Vim.
Sublime Text might freeze when you do this. It’s a bug; just restart Sublime Text after changing
the file.
ctrl+r in Vim means “redo”. But there is a handy Ctrl + R shortcut in Sublime Text that gives an
“outline” of a file. I remapped it to alt+r by putting this in the User keymap
{ "keys": ["alt+r"], "command": "show_overlay", "args": {"overlay": "goto",
"text": "@"} },
Add the ability to toggle Vintageous on and off
Mac users: you will not have the ability to hold down a navigation key (like holding j to go down). To fix
this, run the commands specified here: https://gist.github.com/kconragan/2510186
Now you should be able to restart sublime and have a great Vim environment! Sweet Dude.
Other
I don’t personally use these yet, but I’ve heard other people do!
:wqa - Write and quit all open tabs (thanks Brian Zick)