Vim can be confusing the first time you try it out, but with time and patience you can learn the beauty of using it and gradually shape it to suit you and your requirements. Here are a few things that I did to familiarise myself with Vim without overwhelming myself:

1. Don’t try to learn everything at once

When I started out, I stuck to the absolute basics first and gradually learned new commands as I went along. This is often recommended as the best way to get going - first master the four most basic commands (HJKL for movement) and only move on to another four or five other commands once you’re completely comforable with these and use them without thinking about them.

Tip: Use Vim Adventures to get the hang of the movement commands and then work your way through a cheatsheet and Vimcasts to learn the others, and reference and to learn how to search with more sophisticated regular expressions

2. Version control your files

Vimcasts, a fantastic resource for learning Vim, has a great tutorial on how to keep your Vim configuration files under version control with git. The benefit of this is that you can always replicate your Vim setup on almost any machine and will always have a backup of your precious configuration, plus any previous configurations.

3. Don’t try to set everything up straight away

Once I started getting into the Vim way of doing things, I found that I didn’t really need that many plugins or configuration.


A few plugins, such as Vundle or Pathogen, help to keep your packages nicely organized, while others like Surround and Nerd Commenter simply make some common tasks quicker. Others may relate more specifically to your particular need, but on the whole the base Vim setup can be fairly powerful. Adding plugins is something worth doing gradually, allowing you to get used to what you install and avoiding anything unecessary.


As with the plugins, I found that the best approach was to gradually add to the .vimrc config file as I found a reason to by slowly pulling bits from other people’s Vimrc files (many people have these hosted on somewhere like Git Hub or on their blogs). There are a few general ones that are worth putting in straight away, but many, such as Code Folding settings, are worth adding when you find a particular need to or if you happen to come across them in a Vimrc file of blog post and think that they suit you.


Here are some of the most useful commands to get started with:

/searchword             " Search forwards
?searchword " Search backwards
/jo[ha]n " Search John or Joan
/\<fullword\> " Search full word
/\<the " Search the or then or theatre
/fred\|joe " Search Fred or Joe

Search and Replace

%s/search/replace/      " Basic Search and replace
%s/search/replace/c " Basic Search and replace with confirmation
'<,'>s/search/replace/ " Search and replace only vithin selection (must select text first)

Regex Basics

.                       " Match any character excluding new lines
\_. " Match any character including new lines
{3} " Match only 3 of character match (e.g. search only 3 letter lowercase text [a-z]{3})
{3, 6} " Match between 3 and 6 of character match
* " Greedy Match any number of character range match (e.g. any number of numbers: [0-9]* or any number of any character: .*)
\{-} " Non-Greedy Match any number of character range match
\(pattern\) " Record pattern and reuse in replace with \1 (or \2 for second and so on)
Tip: use Non-Greedy range to avoid matching too many characters (e.g. up to the first double quote: .\{-}")


qq                      " Record macro to 'q' register
@q " Run macro on 'q' register


ma                       " New mark at register 'a'
'a " Go to mark 'a'

Copy and Paste

y                        " Copy (Yank)
p " Paste

Copy and Paste to Registers

"ay                      " Copy to register 'a' (can be a-z or 0-9 character)
"+y " Copy to system clipboard (requires specific version of Vim)

Vim Diff

vimdiff file1 file2      " Diff two files
vim -d file1 file2 " Same as above
]c " Go to next change
[c " Go to previous change
dp " Put change that cursor is on to other file
do " Obtain change from other file


~                        " Cycle Case of selected character(s)
u " Change selected text to lower case
U " Change selected text to upper case

File Navigation

:ls                      " List open buffers
:Sex " Open directory of current file (opens in split window)
:cd directory/name " Go to directory directory/name
:cd .. " Go up a directory
.. also highly recommend the NerdTree plugin

Window Splitting

:vert sb [buffer name]
:split filename " Split window horizontally and open new file inside
:vsplit filename " Split window vertically and open new file inside
:Ctrl-w Ctrl-w " Cycle through window splits
:Ctrl-w l " Go to window on the right (works with all HJKL movement commands)
:Ctrl-w L " Move window to the right (works with all HJKL movement commands)


<<                       " Indent line
>> " Dedent line
= " Auto indent selected text
gg=G " Auto indent from top to bottom


Ctrl-a                   " Increment number under cursor
Ctrl-x " Decrement number under cursor
Ctrl-r Ctrl = " Calculator (useful with 'c' and macros)

Code Folding

Using Vim’s manual code folding with triple curly braces:

{{{..}}}                 " Create fold {{{ start }}} end (use within comments)
zf " Create folding around current selection
zo " Open one fold level (many people remember the 'z' command by the similarity of z to a folded piece of paper)
zc " Close one fold level
zR " Open all fold levels
zM " Close all fold levels

Scroll Binding

:set scrollbind          " Set split windows to scroll together
:set noscrollbind