Page last edited on 2016-12-14
Note: this article was written in 2009—things may have become outdated since then.
As part of my internship at Open Systems, I had to develop on linux boxes without graphical user interface. I had therefore to setup an appropriate development workflow, whose central piece was, of course, the editor. After seeing a colleague performing some "magic" in Vim, I decided that this was going to be my editor of choice. As I litterally started from zero, I thought it would be nice to share the resources that I found the most useful in learning Vim, and this is what this blog post is about.
First, some very basic notes on command line text editors. Vim (Vi IMproved) is, as its name suggests, the descendent of an editor called Vi. From what I've understood, Vi is no more in use nowadays, and Vim offers great improvements (e.g. redo something you undid) over Vi. There is a famous rivalry between Vim and Emacs, a competing editor, which I haven't tried, but which might be an interesting alternative. I have to say, Vim is not intuitive for absolute beginners: you can't just fire it up and expect to be able to edit your file. If you want a very simple and easy to use text editor, I can think of nano (a pico clone), which is far more intuitive than Vim.
Vim has a steep learning curve, but once you're acquainted with it, you'll find that the commands aren't difficult to remember, and it will save you a ton of text edition time. Another advantage is its wide deployment. It is, as far as I know, a more or less standard tool in every POSIX-compliant operating system – including, for example, Mac OS X.
The most important thing to get at the beginning: Vim is a modal editor, where the two "most important" modes are
i
from the command mode. Return to
command mode by hitting ESC
A very deconcerting error, and certainly one you'll make when you start (I can't count how many times this happened to me) is to start typing something while in command mode. As nearly every key is associated to a command in this mode, this triggers a pseudo random batch of commands, and you will be totally lost! So beware, and learn to use undo (described below)
Here are the very, very few basic commands you need to know to get your head
out of the water. You can open a file by typing vim file_name
.
Once you're in Vim (in command mode):
:q
exits the program:q!
exits the program and discards changes:w
saves the fileESC
exits from insert
mode and switches to command modei
switches to insert mode (you can then type some text)u
undoNow here's the list of the resources that helped me the most:
vimtutor
– it launches an interactive Vim
tutorial, and it is an absolute MUST!Some more links, courtesy of Victor (December 2016)