Ask YC: Why is emacs a great editor?
I recently installed emacs since a lot of people (yes - yc users) seem to think it is the best code editor around. I read that it has a steep learning curve, but that it would be worth the effort. I accepted that and started using it as my primary editor to get my hands dirty. After 2 weeks of use I'm still not productive in it. I can think of the following reasons for this:
- I use my mouse a lot, and it seems that emacs is made primarily for keyboard input. I don't use keyboard shortcuts much.
- A nice looking GUI and well designed intuitive interfaces matter to me. Emacs is extremely lacking in this respect.
- I simply haven't spent enough time with it - the learning curve is steeper than initially expected.
What do you think? Am I missing something obvious, should I carry on in the belief that this is a divine tool that just takes time to master, or is emacs simply not for me?
83 comments
[ 5.8 ms ] story [ 168 ms ] threadFailing that, have you read the tutorial?
Have you read Steve Yegge's "Effective Emacs"?
If none of that can help or inspire you then I probably don't have much chance. But I'll offer you some coaching anyway. Imagine Vince Lombardi reading this to you:
Stop using the mouse. If you're using emacs and you're touching the mouse, you're doing it wrong.
Stop fretting about the GUI. Why does your editor need a GUI? Emacs is a text editor, a program that is all about text. It's text all the way down. If it had more chrome, that would be wasting pixels that could be devoted to text. (Seriously: As Yegge will tell you, the true emacs user turns off the pull-down menus to make more room for text.)
Stop worrying about "intuitive". Yes, until you get to know the moves, emacs is nonintuitive, kind of like the piano. No matter how expensive and well-designed a piano I buy, I won't be able to just sit down and play some Chopin. (Well, technically you can buy player pianos that will do just that, but what would a concert pianist call such an instrument? A toy.) You're learning an open-source text editor that's quite possibly older than you. You will live with this software for months, years, or decades. You don't need features that make it easy to learn emacs in five minutes. You need the features that make it worthwhile to use emacs after thirty years.
And, yes, you haven't spent enough time. In particular, it's not just a matter of plugging away in emacs for weeks or months; it's unlike any other software you've ever used, and until you're oriented you won't find it easy to pick up things just by playing with it. You have to study it a little. Try some of the references. Try the Emacs Wiki.
One thing I really love in Emacs is that every text is basically displayed in a buffer, regardless of it being editing text, external program output, file listing, menu items or completion candidates. It means you can use common editing commands (incremental search, region selection, copy&paste, etc) uniformly to navigate those information. It's all text, so you should be able to do so. Then I turn to a supposedly intuitive GUI app that shows a menu with 100 items and I'm just lost since I cannot regexp-search through those items.
- Initial user experience is (very) secondary to long-term efficiency
- if you aren't in this for the long term don't bother - the article actually suggestes swapping the caps lock key and the ctrl key to have it better positioned for emacs use...
- unplug your mouse, the keyboard is faster once you learn how to do it well.
It seems to me that Emacs is a friend for life, but only if you have the patience for a year or two of courting and learning its tweaks and quirks.
I'll buy O'Reillys book and see how it goes.
But there's certainly years of material left after that, if you want it. After eight years off and on I still haven't touched a sizeable number of emacs features.
Precisely. You can get productive with emacs after a relatively short period of time, but you will have a lifetime of learning afterwards. After 10 years, I'm still discovering new things.
UNIX/Linux users have considered this mandatory forever, regardless of editor choice. PC keyboards are simply wrong.
The optimal solution I've come up with is to use the two keys adjacent to the space bar (typically Alt, but actually Command on the Apple keyboard I generally use) as Control, since that's easily the most important modifier key, so it should be the easiest to access. This makes C-w, C-s, C-r, C-a, C-e, C-p, C-o, C-j, C-l and so on very, very comfortable compared to the corner positioning. As far as I know, this is the way many keyboards were before the extended IBM PC keyboard came up with its insane control key positioning. (My comfort with these keys may also be linked to my use of Macs and ubiquitous command-key shortcuts before I switched to Ubuntu. Ironically, Emacs is much more comfortable now in Ubuntu than it ever was on my Mac, because I can use the most readily accessible modifier key as God intended, rather than the third-tier relegated modifier that Control is on the Mac.)
The two keys adjacent to the new Control keys (ie. 2 away from the spacebar) then become the Alt keys. Whatever is left over (the original ctrl keys, plus Caps Lock and any silly Windows keys left over) can be bound to Super, which is useful for window manager shortcuts so that they don't clobber emacs/bash/screen bindings.
These changes are trivially easy to put in a simple .Xmodmap file to load whenever you log in, and copy to all the other computers you have to use regularly. If you're using Windows, I guess you may have to fiddle with the registry, but it would be worth it.
Use the hand that is not hitting the key: for C-s use your right hand for the Ctrl, and left for s. C-n the other way round. For Meta, make sure that both alt keys work, and use your thumbs: M-x right thumb and left fourth finger.
- You can't do this for C-M combinations, but they are few and far between.
- You have to have a keyboard where the keys "stick out" a little. So it does not work on laptops.
The only real issue I had was that moving around is a little slow and awkward: When going back and forth from C-f/b to C-p/n your hands are moving a lot. So I remapped C-f to C-; and C-b to C-j (and similarly for M-f & M-b) and now I can press Ctrl/Meta with my left hand and move around with my right one: bliss.
Also, if you're not using C-M-... shortcuts, you're missing out:
C-M-{s,r} isearch-{forward/backward}-regexp (indispensable)
C-M-% query-replace-regexp (indispensable)
C-M-\ indent-region (indispensable for when M-q would mess up your line breaks)
C-M-x eval-defun (for running changes to your .emacs without restarting)
C-M-q indent-pp-sexp (pretty-print and reindent sexp at point)
C-M-{f,b,u,d,a,e,k,t} forward/back/up/down/beginning/end/kill/transpose sexps
C-M-{n,p} {forward/backward}-list
C-M-v scroll-other-window
And so on. C-h k (describe-key) is your friend.
I would be the first one to buy.
(custom-set-variables '(mac-command-modifier (quote control)) '(mac-option-modifier (quote meta)) )
And now your command key is a control and your option key is a meta.
I'd argue that this is ergonmically essential for long-term emacs use, otherwise you run the risk of 'emacs claw'.
Took me less than a week to get used to it. If you regularly use other people's machines then it's not a good idea (but then, neither is emacs unless you are carrying around your .emacs file, since you'll miss all your personal keybindings).
After that, mapping CAPS-LOCK to be CONTROL.
After that, the previously mentioned O'Reilly book.
> mapping CAPS-LOCK to be CONTROL.
Why? At least in my laptop CAPS-LOCK is easier me to press than CONTROL if I want CAPS, maybe there is another reason for it?
(It also makes Ctrl shortcuts in other applications easier.)
However, when you're at your desk, the most awesome Emacs upgrade is to buy a Kinesis Ergo "Contoured" keyboard (http://www.kinesis-ergo.com/). It moves all of the control/alt/Apple/Meta keys from all of the random locations to your thumbs and so once you get used to it, it's way, way better than anything else.
The only downside is that it only comes in one size so if you have large hands / long fingers it might be too cramped.
For the skeptics, once you get used to it, it's actually quite easy to go back and forth between the laptop keyboard and the Kinesis. I.e., very little mental dissonance.
I use to half joke that my disdain for Microsoft is not as extensive as it may appear from one reading what I post (I got a -8 mod a couple days back for saying no real programmer would accept programming under Windows). In fact, I love several Microsoft products and, for me, the three best products they do today are the natural keyboards, the mice and SQL Server. In that order.
I loved the Z-80 softcard too. Would place it above SQL Server if it were still in production.
Only if you miniscule hands and recordbreakingly narrow shoulders.
What's the purpose of caps lock? If you're SHOUTING you should be HOLDING DOWN THE SHIFT KEY AS HARD AS YOU CAN SO THAT YOUR FEELING IS GENUINE!
There's other documentation included with emacs beyond that, e.g. the info pages. Anything that can be read from within emacs has the added advantage of helping you get used to scrolling and moving around inside buffers (again, hopefully without the mouse).
After working through that, some combination of reading the Emacs Wiki (http://www.emacswiki.org/cgi-bin/wiki) and a recent edition of _Learning Gnu Emacs_ will get you off to a good start.
Getting really effective with Emacs takes a while (probably at least a month), but it is very deliberately designed to be keep growing with you. If you come to prefer it for editing, you can bundle together your config files and extensions and run Emacs on all the major OSs. It becomes its own extensible environment, much like Firefox with its extensions. (This is why the time spent learning it pays off.)
IMHO, the tutorial is useless. It spends too much time on C-p and C-n and not enough time on anything useful.
I recommend reading the Info documentation. It is very well written and very complete. You should also read the Elisp reference manual; having an understanding of the internals is helpful even if you don't intend to program emacs.
Also, it covers some conceptual things upfront, like how C-f is forward-char but M-f is forward-word, and that M-somekey is often a more abstract version of C-somekey. (Also, how to read the "C-x M-c butterfly" style keyboard shortcuts in the first place.) A lot of the things it covers ("C-x C-s is save") are pretty basic, but it tries to introduce some of Emacs's cultural/design quirks, which are probably what really trip up a lot of people.
You're editing text. What "graphical"s are you expecting? (You should be seeing syntax and selection highlighting.)
> well designed intuitive interfaces matter to me.
What's the difference between "intuitive" and "familiar"?
Yes, the keyboard commands are not what you're used to. If you want the keyboard commands that you're used to, you can program them. That's generally a bad idea, but emacs is full of rope.
Let me underline this sentence. Some people (particularly the ones who think that copy and paste were invented by God on the eighth day of creation) get it into their heads that they should redesign the emacs interface on their first day. This is particularly tempting because the ability to remap keys all over the place is one of emacs' best features.
Resist the temptation to do this at first. The emacs ecosystem actually makes a great deal of sense once you settle into its way of thinking. It's sometimes hard to believe, but very smart programmers have spent decades working out where to put things in emacs. If you insist on ignoring their efforts, and instead try to pretend that emacs is a lot like the Mac OS, you will never even learn the basics, like the glories of the kill ring and the mark ring, or the important distinctions between a file and a buffer.
This is especially true for users of other programming-style text editors, such as Vi(m). Using Viper or similar can be a good way to ease into Emacs. It's even structured that way -- you can progress through the levels to gradually transition from Vim's way of doing things to the Emacs way. I did this myself.
As I said, it does require the discipline to periodically learn more and more features to progress. Aquamacs offers a similar transition for Mac OS X users.
Occasionally you'll want to use emacs on someone else's system, usually in their current session. You'd like to be able to do that without customizing their system. Similarly, you want them to be able to use your system/session without undoing your customizations.
* You'll probably overwrite some other really useful keyboard shortcuts unintentionally. C-v (Paste, on Windows) is page-down in Emacs. C-c is the prefix for mode-specific commands; C-c C-c sends email, compiles the function under the cursor, etc., depending on what file / buffer type you're working in.
* Emacs has its own ways to do some of those operations. Copying and pasting under Emacs is fundamentally different because of the "kill ring". Instead of having a clipboard, it has a stack (which loops once you hit the end, hence, "ring").
I've tried to start using Emacs a few times now, and I just can't get this. My keyboard already has page up/down and arrow keys that are accessible without using a modifier. Why would I want to use a two key combo when a single key will suffice? Page jumping especially is something that you're not going to be in a rush to insert text afterwards.
The other thing I don't get is the ridiculous hand-mangling you've got to do for the M-combos. (I'd already remapped caps lock to control)
I understand that many of its standard key combinations precede the keycaps and de-facto standards of today, but I'd hardly consider it a loss for the bindings to fit in better with the rest of a modern system.
I'm about to try Emacs for the third time. Are there any common sets of alternative bindings?
Under Qwerty, most of the common prefix keys (e.g. C-x, C-c, M-x) are scrunched together on the left hand. If you're also using your left hand to press Ctrl (whether on CapsLock or at the bottom left of the keyboard), you're mangling your hand. That's why there's also a right Ctrl key.
FWIW, I sometimes use Page Up/Down and the arrow keys while just reading, but tend to use the Emacs-style navigation shortcuts while actively editing. C-v never made sense to me, either; I'm guessing it's just historical.
When I was in my early twenties, I decided enough of my heroes at the time raved about Emacs that I should just trust them and not care how long it took to learn or how hard it was. This turned out to be a good decision.
Here are some other additional notes:
- You can get it on every platform. I personally use XEmacs (though I'd recommend GNU Emacs for people starting now) and it's exactly the same on Mac, Windows and Linux.
- Many of the old Emacs die-hards learned Emacs in a time when Emacs had just as good a GUI as anything else. So a lot of our rhetoric comes from an era when everything was driven by keyboard shortcuts. I do, however, believe that learning how to use your editor from the keyboard alone does improve long-term efficiency.
My suggestion - stop reading all the tutorials and just do it.
Keep a list next to your computer with 5 things you need to know how to do - with the key strokes next to them.
Once you become comfortable create a new list that is what you need to learn now. Don't over extend (ooh, git integration, org-mode, ...) - you'll get there (and probably within a few weeks) - but focus on the basics first. Once those become muscle memory you can figure out the advanced stuff.
Info has its own manual, but most of what you need to know to start is that Enter visits a hyperlink (which are probably purple and/or bold), 'u' goes up one level, 'n' and 'p' go forward/backwards one node, and 's' searches. (To get a more detailed keyboard shortcut list, type "Control-h m" inside of the info buffer.)
1) emacs is very well integrated with extremely powerful tools (in this case diff, merge)
2) emacs is deep; even as an advanced user you can keep improving your efficiency (albeit at a lower rate)
Having said that, I have a question: once I had become fairly comfortable with emacs I switched back to vi. I felt there was a positive correlation between learning new keystrokes/tricks while coding and the quality of code I produce. Has anyone else observed that? If yes, why do you think this is so?
At some point it becomes clear that emacs is actually a programming environment for text editing with emacs lisp in the position of universal configuration, scripting and compute language. If you can think of something you want to do with text,files or code (albeit limited to an ascii interface) you can either find it in the extension community or you can quickly bend emacs to do what you want.
My learning curve was approximately two years to feel very competent, five or so to feel like a power user, and then 8 or so to feel make it do most anything.
To have an expert Emacs user do a screencast of himself doing standard programming stuff.
I think that would make it really obvious how these types of editors are.
http://www.foldr.org/~michaelw/emacs/
Anyone with a webcam up for the job ?
:-)
Link in the comments from here: http://news.ycombinator.com/item?id=230990
There's another film by the same person about using UncommonWeb (a lisp web framework) that has more emacs goodness. Note the UCW tutorial is probably somewhat out of date as the framework has changed a bit since then. http://bc.tech.coop/blog/050727.html
It isn't--don't believe the hype. On the other hand, I couldn't write a line of code without IntelliSense.
Does anybody know anything about Emacs.Net that Microsoft is working on?
http://www.knowing.net/PermaLink,guid,31fdc849-db2a-4f7d-bf9...
Nope.
The funny thing is, every time I go to write some Clojure code - I want to open a Vim session, but I am always strangely drawn to Emacs for some reason.
Recently, I decided to figure out what it was about Emacs that made me want to use it so much over Vim. I soon realised it was all about being able to load a REPL process in a window and interact with it on the fly.
I can run Emacs, open a Clojure source file, write a function then hit C-M-x to send the function to the REPL to be evaluated. Also relevant is that Clojure support in Emacs was available shortly after Clojure's release to the public late in 200.
This is a very specific case (lisp-style interactive development) but it's why I personally think Emacs is great and for me it has nothing to do with Emacs text editing features! I will always prefer Vim for pure text editing power.
I was a vi guy for a very long time, and I mocked the Emacs guys for "eight megs and constantly swapping" and "Emacs claw" ... until I switched to TextMate on the Mac, and realized how Emacs-inspired it is. It was actually very easy to go from TextMate to Emacs.
Along the way, I got more productive in my shell. Did you know that M-left moves back a word on the command line? I didn't, and I've been using bash for 10 years. Oh, and it works in all readline-enabled apps.
I get frustrated when running a shell in a regular terminal. They all implement some subset of emacs editing keystrokes, but never all of them, and the subsets are different. It's wonderful having all editing, searching, etc. functionality of emacs available when typing in your shell.
I wrote some Emacs Lisp to jump to the line of a javac syntax error, or stack trace line with a single keystroke. Combining that with the ability to run a shell and browse log files comes in very handy. I also have a macro that searches for the Java symbol under the cursor. It misses a bunch of edge cases, but still very useful. All of this in just 55 lines of elisp. How many lines does it take to write "Hello, World!" as an Eclipse plug in?
There are a number of looks that emacs can have, from emacs -nw (runs in your terminal emulator) to emacs with GTK. And there are colour themes within each. M-x color-theme-select
Don't get ambitious and treat it like your favorite editor just yet. Decide on a small task with complexity (and hence requires you to jump back and forth and rename stuff), like a 20-line script. Make plenty of use of the basic keystrokes (C-f forward, C-b backward, C-p prev line, C-n next line, C-s search, C-r reverse search). That's 6 combinations, and it's enough to witness the kind of speed you have in navigating the text.
Then use it for a real editing job. Shouldn't take long before it becomes second nature. Then, it shouldn't take long before you wished that every text entry window used the same keystrokes.
Oh yeah, type return to complete the search.
- No mouse; - No GUI; most people hide even the menu bar; - They have spent and do continue to spend a lot of time in Emacs.
Someone suggested a video recording of an Emacs session. That sounds like a good idea!
Force yourself to move the insertion point with the arrow keys, for starters. Then learn a few shortcuts so you don't go insane. C-a for beginning of line, C-e for end. M-f and M-b for forward/backwards by a whole word. C-v and M-v will scroll you up and down through the document and move the insertion point so that it stays on the screen.
Emacs doesn't need a lot of UI. It isn't an IDE, for one thing (though it can be used as one). Customization is done by putting incantations in your .emacs file. Managing buffers and panes only requires a handful of commands; learn the keys for them, or re-assign them if they're awkward.
Emacs is intrinsically a keyboard-driven editor, and mostly just tries to keep the GUI out of the way. Your experience is more meaningful than anybody's dogma about whether keyboard-centric or mouse-centric development is more productive for you, but mostly using the mouse will make it hard to take advantage of what makes Emacs special.
(If you, or other readers, want to really learn Emacs, you should probably give it at least a month. Once you're comfortable with the basics, gradually learning elisp will greatly increase how useful it is for you.)
Another resource that will be really helpful somewhere in there is to just type C-h C-h. You'll see a listing of various kinds of help. I use these a lot, especially to explore something new:
C-h k (type any keyboard shortcut) "what does this shortcut do?"
C-h b "list all keyboard shortcuts from all modes in the current buffer"
C-h f (type a function name) "what does this function/command do?"
C-h v (type a variable name) "what does this variable do, and what is its value?"
C-h a (type a regexp) "list all commands matching the regexp"
M-x apropos (type a regexp) "list commands, functions, variables, etc. matching the regexp"