Some more comments after using emacs for a while:
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)to your .emacs, so that you can use M-TAB to force the completion menu to come up. This generally happens automatically, but I think this is the only way to get fuzzy matching, for example. Actually, you can also just use
(ac-set-trigger-key "TAB"), which intelligently sets TAB to complete or indent, based on which one you more likely want. This seems to work pretty well to me.
TABrepeatedly, and it cycles through all the syntactically legal indentations. I find this to be more useful than the usual
TABindents behavior of most editors. Note that by default, it won’t automatically indent, even with trivial indentations (i.e., keeping the previous indentation). This is easy to fix, though. Just add
(define-key global-map (kbd "RET") 'newline-and-indent)to your .emacs file. This will make
RETdo the same thing as
C-j, i.e., basically the equivalent of
But unlike all the other hundreds of emacs features that I don’t use, this one was seriously slowing down my workflow. It adds three or four seconds to the startup time of emacs when loading from within a git repository. So I did some Googling and added this to my .emacs file:
;; Disable all the version control stuff ;; Makes emacs load much faster inside git repos (setq vc-handled-backends nil)
(unrelated: Why doesn’t WordPress support lisp as a language for syntax highlighting?)
This disables the version control stuff, making emacs load fast again (virtually as fast as vim, actually).
M-x byte-compile-filefrom within emacs. Just make sure that if you modify the .el file that you recompile the byte code, or it will continue to use the old version.
;; ===== Enable mouse support ==== (require 'xt-mouse) (xterm-mouse-mode)
in your .emacs file. And then it just works. It needs some tweaking (e.g., it doesn’t play so well with momentum scrolling), but at least it works. I thought I was going to hang myself without mouse support. Because frankly, as good as the movement commands are, moving with the mouse is so much easier sometimes (the same is true for vim too, btw).
emacs -nw. I’m sure I just need to add some flag to
configure, but I haven’t gotten around to looking it up yet.
;; ===== isearch+ ===== (require 'isearch+)
and most importantly, you need to edit the file and uncomment all the commmands you want to allow. If you follow my link above, it goes to my personal dotfiles repo, where I’ve already done that.
On the other hand, with vim, I had to edit virtually every extension I installed to make it do what I want. I’m not sure what this means, though. It could be a statement about one of many things: how the emacs community provides nicer defaults, how the vim language is easier to use, and hence more inviting for me to edit the files, or how I haven’t gotten around to messing with certain things yet.
M-x customize, and reading my
.emacsfile. And my best advice: if you want emacs to do something, first do
M-x customizeand search for what you want (EDIT: apparently searching customize requires emacs 24, i.e., the development version). If you don’t find what you want there (and you will surprisingly often), search Google. There are so many emacs users, that the chances of someone else wanting what you want are very likely. I’ve found the results from the emacs wiki to be particularly helpful. And one more thing: if you find an extension you like, double check first to see if it’s not already included in emacs. Emacs seems to like including good extensions in future releases, so an older extension has a good chance of already being included.
Some emacs questions:
(define-abbrev global-abbrev-table "Ondrej" "Ondřej"), so that when I type Ondrej it give me Ondřej. But it doesn’t work. Is this a bug or what? If I do
(define-abbrev global-abbrev-table "foo" "bar")and type “foo”, it turns into “bar”, but the above leaves Ondrej alone. EDIT: I guess this was an emacs bug. It doesn’t seem to be there any more (perhaps it was fixed with the git version or something).
M-x load-file RET ~/.emacs
This Tuesday will mark the point where I will have spend as long using emacs as I did using vim. But already, I feel more competent with emacs. I won’t repeat what I said in my last post, but I just want to say that the ability to edit and write at the same time makes me way more productive. The fact that it uses keyboard shortcuts that I’m already used to probably helps a lot too. Even so, I’ve not used any kind of cheat sheet for emacs (since I never really found any that were any good), and yet I feel like I’ve memorized more key commands now than I ever did with vim, for which I did use a cheat sheet.
So I really don’t see myself going back to vim at this point.
I’m actually surprised. Virtually everyone I know who uses a command line editor uses vim. It’s definitely the more popular of the two. But having tried both, I can only speculate as to why. Vim has a much higher learning curve than emacs. Everybody grows up learning how to write text in editors like Microsoft Word, TextEdit, Notepad, etc., that all work fundamentally like emacs: if you type text, it enters the text. If you want to do advanced editing with the keyboard, you hold down some meta keys and type chorded keyboard shortcuts. The vim modal editing methodology is so different from this, that it surprises me that so many people go to the trouble of learning it (I mean, to the point that they are more efficient with it). I can see the benefit over GUI editors, which have nothing on either vim or emacs with regards to customization, or just the plain editing power that is really necessary for coding. My guesses why people use vim:
Maybe the vim users out there could comment why they use vim. Am I missing something? Or are your heads just wired differently from mine? And if you use emacs (or anything else), I’d love to hear from you too?
At any rate, I recommend that anyone who wants to give command line editors a chance do what I did: learn both vim and emacs. My blog posts should be enough to give you some good advice. I went cold-turkey, and I recommend that you do too, but only do it if you won’t have any important editing to do for a few weeks, as your editing rate will slow down a lot as you are learning for both editors. And even though I think I am going to stick with emacs, learning vim was still valuable. Unlike emacs, vi is part of the POSIX standard, so it’s included in pretty much every UNIX distribution. I’ll be glad when I find myself on a minimal command line and know how to use a decent text editor. And anyway, you can’t really know which one will be your way until you try them both. I really thought I would end up using vim, as it was so popular among all the people I know who use command line editors. But I guess there is only One True Editor.
EDIT: I found out how to make emacs really fast. The key is to run one process of emacs in daemon mode, and have the rest connect to that. Then you only have to wait for the startup once (per computer session). To do it, just set your
'emacsclient -a "" -nw' (and you might also want to alias
emacs to that as well). What this does is connect to the emacs daemon. The
-a "" starts one if it isn’t already started (you can also do this yourself with
emacs --daemon. If you only want to use the daemon version if you’ve specifically started it, replace
emacs. This will connect to the daemon if it’s running, and otherwise just start a new emacs process.
-nw keeps it from running in window mode. Remove this if you use the GUI version of emacs. This is necessary to make it work correctly with multiple tabs. This is so fast that you should never really even need to use
C-z to quickly exit emacs.
C-x C-c is just fine, because reopening will be instantaneous. I like this because I was starting to accumulate background emacs processes that I forgot about.
This probably requires a fairly new version of emacs, possibly even the development version.