Vim Most Used Commands 16 Dec 2013
Lately at work we’ve been using a combination of vim/tmux to make pair programming a lot easier. This is especially helpful when working remotely or under a crappy internet connection, as you won’t need a lot of bandwidth.
While both vim and tmux allow you to highly customize your shortcuts, changing them too much will make your pair’s life harder, since they’ll have to memorize your specific shortcuts, so keeping the defaults will make everybody’s lives easier.
vim is a big beast on its own, but in a good way. You can find a huge number of plugins out there that will make you go crazy, so to keep sanity levels to a maximum, I use a single one: Janus.
Janus bundles together a lot of really useful plugins to make a devs’ life simpler (fuzzy search, ack, git commands, additional syntaxes, and more). As such, most (if not all) shortcuts I list here will really only work with it:
:new # open a new file
:e path/to/file # edit specific file
:w # save file
:q # quit/close file
CTRL+p # fuzzy search and open file
:%s/search/replace/g # search and replace
:Ack <search> # find <search> in all files
:set foldmethod=indent # fold according to indent
:set foldlevel=1 # defaults to folding first level
CTRL+w v # split window vertically
CTRL+w s # split window horizontally
CTRL+w <move> # move between windows
\n # open file tree
H # Move cursor to top of the screen
M # Move cursor to middle of the screen
L # Move cursor to bottom of the screen
CTRL+d # Move half a page down
CTRL+u # Move half a page up
d<move> # delete <move>
y<move> # copy <move>
c<move> # change <move>
. # repeat last command
zO # open all folds under cursor
zo # open first fold level under cursor
zc # close current fold block
zx # close all but current fold block
<< # unindent line/block
>> # indent line/block
p # paste contents after/before current line
gg # move to first line of the file
G # move to last line of the file
w # move one word forward
b # move one word backward
t<char> # move just before <char>
f<char> # move to find <char> in the current line
^ # move to first character in the line
v # create visual block
V # create visual block with whole lines
CTRL+v # create a vertical block
\gb # git blame current file
\gs # git status
These are all the commands I can remember using all the time. I believe this short list will make it possible for the newcomers out there to try and give vim a change and get passed the –incredibly– steep learning curve (compared to other, more visual, editors out there).
Let me know if you have any commands that you use all the time as well!