Preface
In case you didn't already know this.. the choice of editor to a geek means more than the choice of religion to the average person. Flame wars over editors are legendary and go back decades. The Unix community split into two main currents, each following one special editor. As you would have it, these two currents are about as black and white as you can find, exactly as the two editors also are: vi
and emacs
. They are on either extreme of the spectrum. emacs
(1975) was written by Richard Stallman and friends, and aims to be everything. It can integrate with lots of other applications, shells, you can run everything *inside* emacs
, never having to leave the editor! vi
(1976) aims to be nothing, it is the anti-thesis, written by a sadistic bastard called Bill Joy. :D It is as cut down, crippled and bare bones of an editor as you couldn't imagine. And so the wars have waged, emacs
vs vi
.
Both editors are super popular to this day. You will find vi
on *every* Unix system. If you have to edit a config file on some ancient machine and you find out your editor isn't installed, eventually you'll have to fall back on vi
. emacs
isn't always included, because of its size. Depending on how heavy the install is, it can easily be 60mb, which for an editor, on a scaled down system, is unacceptable. vi
is about 600kb.
That is not the whole story, however. A pragmatic Dutchman called Bram Moolenaar decided to liberate the world from vi
and came up with vim
(1991): Vi IMproved. Now, ironically perhaps, vim
is much more of an emacs
than a vi
, it has a gazillion features. Still, it's much lighter, and compared to emacs
, still lightweight. With all its extensions and plug ins, it's hard to call it a lightweight editor in absolute terms, because there are lots of smaller ones, like nano
.
Choosing an editor
Since I started out with Linux around the turn of the millennium, and not in the 80s, I don't have such strong feelings about vi
and emacs
. I could care less. I'm happy to use kate
most of the time. It's a very well designed editor, easy to use, intuitive, pleasant. But since I'm hacking Haskell a lot these days, and Haskell is just esoteric enough to not be supported by anyone, I've come to realize that, indeed, it's a choice between emacs
and vim
.
I'm told there is a Haskell mode for emacs
, and probably quite a good one, because it's advertised by the Haskell people. On the other hand, if you search long enough, you might just find some support for vim
stashed away in a corner. Syntax highlighting isn't the problem, everyone can do that. But Haskell's indentation is hell, and the vim
plugin makes it a little better. I've seen Haskell mode for emacs
in action, and that too is rather imperfect.
I reject emacs
on the same grounds as every vim
user in the world. The key bindings are just horrible. Ctrl+X Ctrl+S
to save the file, Ctrl+X Ctrl+C
to quit. That's already painful if you do it once, it's unbearable if you do it while hacking, every two minutes. In addition, I work in X all the time, and emacs
' gui is just awful. Whether it's gnu emacs
or xemacs
, they both stink.
UPDATE: Last night I saw a note about emacs-cvs having a completely new gui, so perhaps that is something worth exploring at some point.
So the choice falls on vim
vim
is not the guy who approaches you with a smile and an outstretched hand. It's the guy sitting in his cubicle consumed in his work and mumbling to himself. What originally got me interested in vim
was not the strong endorsements from lots of people I had talked to it, it was actually this blog entry from a guy who's selling vim
integration plug ins for things like Visual Studio. There were two things about his text that resonated with me. First of all, if anyone is going to be looking for vim
plug ins for probably the most popular IDE out there (ie. lots of people are already very happy with this IDE), there must be something pretty special about vim
. And secondly, he loves vim
because it's ergonomic. Hah, ergonomic, imagine that! Have you ever tried editing away from your desk? It's awful, you don't know what to do with the mouse, the mousepad sucks, you can't use the desktop normally, bleh. But he said vim
works just as well on the train as it does on your desk. That got me thinking.
So does it? I don't know. You see, vim
is a lot to handle. It's like having a particle accelerator dropped in your lap. (And it's just as heavy too!)
Yes, there's a manual, but by the time you read it and grasp the meaning, you'll be an old man. vim
's premise is radical to everyone who uses the mouse to edit. You don't need the mouse, don't touch the mouse, you can do everything from the keyboard. I'm still not comfortable with h,j,k,l, I cling to the arrow keys. I try to force myself to use k instead of arrow-up, but it feels so unnatural. vim
's gui isn't much to brag about either, it looks better, but it doesn't exactly do much for you gui wise.
And, of course, the number of key combinations to remember is completely overwhelming. You just can't learn vim
, you have to take it one day at a time. In fact, that's what Moolenaar says too - today you learn something that helps you today, tomorrow you learn something that helps you tomorrow. So I feel like the journey has just begun, I know almost all the keys on the cheat sheet now, plus a few more.
Configure or die
Unfortunately, the biggest drawback with vim
(and probably emacs
) is configuration. It can do almost everything, but that doesn't necessarily help me. I need to tell it what I need it to do. My .vimrc
is now 67 lines and growing. And if there's one thing I truly dislike about complicated applications it's this - having to configure it down to the smallest detail. And having to carry your config everywhere you go, otherwise all the pain that went into setting up these options is lost once you get on a machine where you don't have your setup. KDE solves this problem now (at least for me) quite well, it's configurable to death, but the defaults are so good that most things I don't have to change (or even know about). Not so with vim,
not only aren't the options listed, it's not always that easy to figure out what they mean.
Depending on the machine, the default vim
config may even have vi
compatibility set, so yes, your vim
is reduced to vi
, how terrifying! Why Bram decided to include a vi
compatibility mode one can only guess, but one suspects it was so that he could argue that vi
lovers could still breathe, meanwhile he would rescue the rest of us from that terror. I can imagine this would be the only way he could make a case to every distro out there to include vim
by default.
So .vimrc
is not exactly a walk in the park, it's quite a mess, and the more you want to configure it, the more muddled it becomes. The first thing I wanted to fix was saving the file. By default in vim
, this is accomplished with an emacs
like awkward sequence of <Esc> : w i. Yes, four key presses, just like emacs
. I managed to map it to one key: <F1>. Out of all the commands I type in vim
, it's the one I use the most and I can't stand that :w stuff, often typing :W by mistake, which gives an error. :lazy: If you want to know how that's done, look no further:
map! <F1> <ESC>:w<RETURN>a " insert mode
map <F1> :w<RETURN> " normal mode
Yes, at least the mapping is pretty obvious, you tell it exactly what you would normally type. It's just that there are a dozen different kinds of map command, apparently this map! is a way to get something working with insert mode. :/
But vim
is not too bad, certain features make you realize that kate
has weaknesses that the mouse can't solve. Like navigating word-for-word (instead of by character), deleting whole words, paragraphs.. generally it's things that have to do with moving in the file that are more sophisticated. To fix a typo in kate
, you could either double click to select the word, delete and type it in - or just click at the incorrect character and replace it. In vim
you hit w to move word-for-word until you come to it, then hit c w (change word) to erase it and you can type it in. That's quite convenient in code. To duplicate a line: Y p, in kate
: Home Shift+End Ctrl+C End Return Ctrl+V. Depending on what you're doing, *a lot* more convenient.
Of course, I'm still trapped somewhere in between, so I'm seeing the flaws in mouse oriented editing, without knowing all about the vim
approach, so it's still awkward. If I had to edit a file to save my life, I would pick nano
. But hopefully vim
does actually work as well as people say and I'll be fluent enough to hack plug ins and make it work well for me.