Starting out with vim
Below is a list of complementary resources and tips that I would have benefited
greatly from when I first starting using vim
. It is a great text editor, but
the learning curve is steep, and its usage seems almost esoteric to the
newcomer.
I hope this will help you off to a better start :) I assume you have already
installed vim
.
Vim is not an IDE
This may not be evident from the start, especially since tons of people use
vim
for programming. vim
is primarily a text editor which is where it
really shines. However, there are tons of plugins available that provide
IDE-like capabilities for vim
among other things. See the section on
plugins
vimtutor
This was something I discovered all too late, but still read through. Go to your
command-line and type vimtutor
. A pager should open displaying a basic
introduction to using vim
.
vimcasts.org
These screencasts are simply indispensable and narrated by Drew Neil in a clear and concise manner with on-screen keystrokes (using keycastr), and complementary notes below the video. They start of with the basics like navigation and modes, then turn to more advanced material like managing and using plugins, and using folds and mappings.
Drew has also authored a book called Practical Vim and does online and in-person workshops. Consider donating.
Although I personally have not seen them, Derek Wyatt also has a couple (28 of this
writing) videos. They may work better
for you, and do touch on topics not covered by Drew’s casts (such as coding
scala
in vim
).
help, helpgrep and verbose
vim
has builtin capabilities for displaying help regarding pretty much
anything in the editor. For example, open vim
and then type :help rot13 |
only
. You will be presented with a help page than explains how to rot13
encode text. The | only
part of the command, ensures that the page is the only
active window (try omitting it).
helpgrep
is another useful command that greps for a pattern in all help pages,
as its name implies. Try running helpgrep ?
.
Finally, the verbose
command will display information about a mapping,
including where it was last defined which is useful for debugging if a plugin
has accidentally overwritten one of your mappings.
Vim Adventure Game
A fun little adventure game created to teach
people vim
. Only the first part is free, but it is still a nice way to learn.
vi.stackexchange.com
A stackexchange subsite entirely dedicated to
vi
, vim
and other editors.
Plugins
vim
features tons of plugins. There is the official
site and here’s another
slightly fancier one. They can be a great help and
usually fill in the gaps that you may be feeling are missing from vim
.
Personally, I installed and learned to use plugins one at a time. Below is a list of my installed plugins during this writing, that you can start looking at.
- colorizer
- ctrlp.vim
- delimitMate
- fsharp-vim
- haskell-vim
- neocomplete.vim
- nerdcommenter
- nerdtree
- seoul256.vim (colorscheme)
- syntastic
- tagbar
- vim-abolish
- vim-airline
- vim-dispatch
- vim-easy-align
- vim-fugitive
- vim-hybrid-material (colorscheme)
- vim-markdown
- vim-one (colorscheme)
- vim-quantum (colorscheme)
- vim-repeat
- vim-scala
- vim-surround
Continuously update your .vimrc
If you don’t know where to start,
vim-sensible
is a good place to
start. It is a barebones, sensible (hence the name) starting point that
contains some mappings and settings most people would find useful. I also
recommend adding the mappings below to easily open and source
your .vimrc
.
I constantly found awesome mappings, functions and other tricks that I added to
my .vimrc
as time went by. You
can use the following mappings to easily open and source your .vimrc
:
" Shortcut for editing the vimrc file
nnoremap <leader>vh :sp $MYVIMRC<cr>
nnoremap <leader>vv :vsp $MYVIMRC<cr>
" Shortcut to reload the vimrc file
nnoremap <leader>sv :source $MYVIMRC<cr>
Now you can simply press your <leader>
key followed by the given characters to
open your .vimrc
in either a horizontal or vertical split and source it again
without having to leave vim
. Don’t worry if you don’t understand the mappings.
This is a great use case for the help
, helpgrep
and verbose
commands.
Also make an effort to make your .vimrc
portable so it is easier for others to
use or for yourself if you copy it to another system with a different version of
vim
. For example, my current default colorscheme is
bubblegum-256-dark.
which I set in
my .vimrc
like so:
try
colorscheme bubblegum-256-dark
catch
endtry
If the command was not wrapped in a try-block, it would fail on systems that did not have the colorscheme available.