anntoin.com
Learning Vim
Learning Vim
Learning Vim is occasionally frustrating, but can improve your productivity, save time and make you more physically attractive. :)
A word of warning, if you want to learn Vim be prepared; it’ll take a while to get comfortable with and you certainly won’t be able to master it in an evening, or even a week. My advice is start off with some of the resources below and once you have mastered the basic movement keys just try to add a command or two at a time. Before you know it you’ll be editing like a pro.
About Vim
Vim was created by Bram Moolenaar initially as a Vi clone on the Amiga, it first stood for Vi iMitation, however when its feature set surpassed the original at version 2, the meaning changed to Vi iMproved.
At first some of the keybindings in Vim can seem a little odd. If you see the keyboard that Vi (and Unix) was developed on, some idiosyncrasies become clear - like using h,j,k, and l for movement keys (notice the arrows). Also see the Unixism of the ~ symbol representing the users home directory.
This article has more info on classic keyboards and their influence on shortcuts/interfaces.
Typing
Are you a typist? I highly recommend that you learn to touch-type. Vim’s interface is designed around key commands that are easy to access from a normal typing position.
If you’re not convinced, read ‘programmings dirtiest little secret’ which finally got me out of the ‘there’s too many key combos/shortcuts to use - touch typing isn’t important for programmers’ mindset.
I’m not normally a fan of web apps for this sort of thing but I found Typing Web a very good guide. Some people find that games like typespeed help too.
Getting started
I’m not going to give a ‘first tutorial on using Vim’ as there are loads of good ones out there. I’ll just make a few suggestions that I found most effective for me in becoming proficient in the One True Editor.
1. Start with the Basics
You should start with vimtutor. After you have Vim installed just type vimtutor
in your terminal and follow the instructions. Go over it a few times until you get comfortable.
2. Have a Reference
I’d recommend printing out a cheatsheet like this one and keeping it to hand at your desk. Have a quick read through so you become familiar with some of the possibilities. It’s convenient if you forget a command, and it makes it easier to expand your repertoire if you have the information to hand.
3. Play Games
There are some games that have Vi-style navigation keys which can be a good way of getting used to them. One of my favourites is WordWarVi; an old school arcade game like Defender. Also worth a look is Vim Adventures; a browser based Zelda-style game where you unlock commands as you go, although you must pay for the full game.
Here are some other good resources I’ve found that can help you get started learning Vim:
There are a few well-paced guides on linux.com. The first one is Vim 101: A Beginner’s Guide to Vim.
Openvim is an interactive online tutorial which gives a good overview of the main keys. There’s a sandbox area so that you can practice what you learn - handy if you’re not comfortable enough in the real Vim yet.
Vimcasts. There are lots of well produced video guides to using Vim here. The guy that does it has also started doing a intermediate level online course.
Vim Regex. When you get comfortable with the basics you should explore Vim’s extremely powerful regular expression support. This is a good tutorial to get you started.
Applications with Vi(m) keybindings
Vi(m) key-bindings pop up in a surprising number of places, Gmail for example. There’s a plugin for Visual Studio too I believe. If you really like Vim (and want to confuse people using your computer) here’s some other applications that use Vi(m) keybindings:
- Vimperator: A Firefox plugin to make it behave more like Vim.
- Zathura: A pdf viewer.
- Bash: Not everyone is aware of this (it was a surprise to me) but Bash’s default key-bindings are emacs-like. To set them to a more sensible arrangement (vi-like), use
set -o vi
from the prompt, or put it in your~/.bashrc
to make it permanent. - Tons of terminal apps. In fact everything that uses the Readline library. Just put
set editing-mode vi
in your~/.inputrc
. - Ranger: A really nice ncurses based file browser that uses miller columns.
- Eclipse The editor can use Vi keys. There is also the Eclim Project (Eclipse + Vim) for serious integration.
:wq
‘KB Terminal ADM3A’ by Stuart Brady from Wikimedia Commons ↩