For a few years now, I have been using Vim to edit config files, program in C, Python, even Lisp (people apparently think that Vim isn’t the best for programming in Lisp). This isn’t because I took a side in the so-called “editor wars”, it’s just because it came preinstalled on the first GNU/Linux system I used, Debian. Over time,
I abandoned IDEs and moved to a full Vim setup, which works well for programming in C and Python, which is what I do most of the time. I like to think my text-editing environment is actually quite good, and that Vim’s modal editing model has aided my programming. But there was always the elephant in the room - Emacs. I had always heard about it from the usual “Why I use Emacs” and “Vimscript considered harmful” blog posts but I had never used it, mostly because I was too entrenched in Vim’s editing model. Then I heard about evil-mode and viper-mode, the Emacs vi emulation modes, and I wondered whether Emacs’ sheer flexibility was a good reason to use it. It seemed that this was the reason most people used it (not specifically for vi emulation, but for the many, equally exciting modes), so maybe I should try it out.
For the uninitiated, here is a quick rundown of Vim. There are 2 modes you need to know about: Insert and Normal. Normal mode is the mode you are supposed to spend most of your time in: you can execute motions, editing commands, macros, searches, everything you need to edit text apart from actually inserting (typing) any text. Insert mode is entered by typing “i” and exited by typing ESC. Between these actions, you can type text and it will be inserted into the file you’re editing. Most newbies attempt to spend most of their time in Insert mode, but this eschews the real power of Vim, the easy composition of motions and commands that allow efficient editing. For example, to delete the next 10 words in Normal mode, you type “10dw”. In Insert mode, you must tediously hold down the arrow key and backspace. It gets better, too, you can delete everything in quotes with “di’” for “delete inside ’” and so on.
Emacs has a completely different model, when you type anything, it appears in the buffer, just as if you were in Gedit, Kate, or any other “normal” editor. Emacs is just as powerful as Vim, however, it just relies on a system of key chords to execute commands and motions. For example “C-k” deletes to the end of the line (C- means hold down Control and press a key, M- means the same thing, but with Alt), and “C-s /” moves to the next "/". Some might say that these key chords have a habit of twisting your hands into unnatural positions, but the advantage of having a built-in Lisp interpreter is that you can script anything you want, however complex, resulting in the included viper-mode and easily installable evil-mode, which “fix” Emacs for Vim users.
I haven’t opted to go for any vi emulation mode in my use of Emacs, I’m using Emacs as Stallman intended. Surprisingly, my hands don’t hurt as much as I thought they would, and I certainly don’t have RSI or any wrist injuries. The first thing I noticed when I opened Emacs was…well, just look at this:
It’s not very pretty, not in the slightest. The first order of business was to change the colour theme. It was not immediately apparent how to do this using the ".emacs" init file, so I resorted to using the GUI, which was quite a bit easier. While there, I also changed my font and hid some of the GUI elements, so it almost looked like a terminal, but with more colours and variable font sizes. Surprisingly, saving the settings did not save them in some unreadable binary format or weird markup language, it just appended some elisp (Emacs Lisp) to my ".emacs" file, which was nice. Here is the result of that:
(custom-set-variables '(blink-cursor-mode nil) '(custom-enabled-themes (quote (wombat))) '(inhibit-startup-screen t) '(tool-bar-mode nil) '(tooltip-mode nil)) (custom-set-faces '(default ((t (:family "Terminus" :foundry "xos4" :slant normal :weight normal :height 90 :width normal)))))
Now I had to get line numbers, which was as simple as appending
(global-linum-mode 1) to my ".emacs". To get a space between the numbers and the buffer text (which isn’t the default, oddly), I had to append
(setq linum-format "%d "). At this point, Emacs was starting to look good. Its real test would be the ease of use of its package system. At the end of all of this customisation, my Emacs looks like this:
Emacs comes with a package manager called, imaginatively,
package.el. It doesn’t come with a very expansive list of repos, so I added a few, using the example on the EmacsWiki to guide me. Here is what I had to add:
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") ("marmalade" . "http://marmalade-repo.org/packages/") ("melpa" . "http://melpa.milkbox.net/packages/")))
Now I had 3 repos to install my favourite packages from. I needed something to auto pair parenthesis and the like, so I installed autopair, which was as simple as “M-x package-install autopair RET”. You can also browse a long list of all packages using “M-x list-packages”, and search it with the usual C-s and C-r. This is better, in some respects, than my method of managing Vim bundles. Vundle requires you to edit ".vimrc" and add something to a list of bundles, then run ":BundleInstall" in Vim. This is a longer process than Emacs’ centralised package repo system, which is more convenient. On the other hand, Vundle lets you install bundles from any Git repo, meaning it’s a lot easier to install random bundles you find on the internet. I haven’t noticed anything regarding plugin/bundle/package quality, all of the extensions/add-ons/scripts I use are quite good, probably because they’re all free software and anyone can contribute. That’s one thing all people on all sides of the Editor War can agree on.
I can’t really say anything about Emacs until I use it more, but I do like the windows more than Vim’s odd buffer system. That’s all for now. Maybe I’ll have more of an opinion when I get to writing large projects.