Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I read a lot about vim and emacs and how they make you much more productive, but I didn't know which one to pick. Finally when I decided to teach myself common lisp, the decision was straight forward: everybody says that there's no better editor for common lisp, than emacs + slime. So I started with emacs tutorial and immediately I ran into something that seems very unproductive to me. I'm talking about key bindings for cursor keys:

forward/backward: Ctrl+f, Ctrl+b
up/down: Ctrl+p, Ctrl+n

I find these bindings very strange. I assume that fingers should be on their home rows (am I wrong here?), so to move cursor forward or backward I should use my left index finger and for up and down right pinky and right index fingers. When working with any of Windows IDEs and text editors to navigate text I usually place my right hand in a position so that my thumb is on the right ctrl and my index, ring and middle fingers are on the cursor keys. From this position it is very easy and comfortable to move cursor: I can do one-character moves with my 3 right fingers, or I can press ctrl with my right thumb and do word-moves instead. Also I can press shift with my left pinky and do single-character or word selections. Also it is a very comfortable position to reach PgUp, PgDn, Home, End, Delete and Backspace keys with my right hand. So I have even more navigation and selection possibilities. I understand that the decision not to use cursor keys is to allow one to use emacs to connect to remote terminal sessions, where these keys are not supported, but I still find the choice of cursor keys very unfortunate. Why not to use j, k, i, l instead? This way I could use my right hand without much finger stretching. So how is emacs more productive? What am I doing wrong?

share|improve this question

closed as primarily opinion-based by MichaelT, gnat, Kilian Foth, Bart van Ingen Schenau, Michael Kohne Mar 3 at 14:35

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

    
You always have the option of using viper and have vi keybinding in Emacs. –  Pedro Romano Nov 13 '12 at 22:51
    
@Pedro Romano, I'm curious about why these keys were chosen as default settings. I suppose many emacs users do use these bindings. It would be strange if everybody would change the basic key bindings and nobody would use the default. And if I were to use vi key bindings in emacs wouldn't it be easier to install vi in the first place? –  Max Nov 13 '12 at 22:58
    
I believe it's because they are mnemonics for the English words, f - forward, b - back, p - previous, n - next. Also you have to remember that Emacs in its default configuration is not a modal editor like vi, so i, j, k, l without a modifier key wasn't really an option for cursor movement. Also swapping the Caps Lock and Ctrl keys will be typical among power users. –  Pedro Romano Nov 13 '12 at 23:08
    
@Pedro Romano, yes I understand the the letter keys would have been used with some modifier(s). My point was that the i, j, k, l key arrangement would be much more comfortable than the f, b, p, n. –  Max Nov 13 '12 at 23:27
    
I found the following article which is enlightening: Why Emacs's Keyboard Shortcuts are Painful. Basically, historical reasons. –  Pedro Romano Nov 13 '12 at 23:32
show 1 more comment

4 Answers

These key bindings date from the early 70's, or perhaps before. They were intended to be mnemonic: F for forward, B for back, N for next, P for previous.

I have been using Emacs since 1976, and prefer it for almost everything except Java programming. But I do find the control combinations tiring on a regular keyboard. At work I use a Kinesis Contour keyboard, and rebind the keys so that control and alt are convenient to my left thumb.

The arrow keys, page up, page down, home, end, delete, and backspace should all work.

How is Emacs more productive?

What are you comparing it to? I find Emacs more productive than other editors because:

  • It is highly customizable. It is programmable at two levels: immediately with keyboard macros, or more powerfully with Emacs-Lisp. Emacs customizations have saved me hundreds of thousands of keystrokes and hundreds of hours of tedium.

  • It doesn't require planning ahead. There is no distinction between delete and cut. To move text, you just delete it in one place, go to the other place, and yank the deleted text.

  • Cursor motion, search/replace, and other primitives just work better than they do in most other editors I have used.

share|improve this answer
    
I understand that emacs is very customizable. But when writing code I constantly find myself moving my cursor around and I think it's a very significant part of working with a text. I thought that the point of binding cursor keys to letters was to avoid removing the right hand from the home row. Do you use arrow keys or Ctrl-b,f,p,n for cursor moves? –  Max Nov 13 '12 at 23:23
1  
@Max: mostly I use control combinations, but I have a programmable keyboard so there is no hand strain. BTW, often the fastest way to move the cursor is via Control-R or Control-S (incremental search backward / forward). –  kevin cline Nov 14 '12 at 3:20
    
@Max Speaking only for myself, I mostly use the "move on syntactic unit" command (word forward/backward, statement forward/backward, move-by-search, move-to-specific-line; and to some extent "move to next compilation warning"). –  Vatine Nov 14 '12 at 13:53
add comment

Emacs has configurable keybindings. If you don't like the defaults, change them.

Here's some stuff that demonstrates a number of lisp-specific commands for navigating by s-expressions, deleting s-expressions, closing all open parens, etc. It's been awhile since I edited lisp, but I remember the M-( command (which wraps the next item in parens) being very useful. If you give it a numerical argument, then it will wrap the next n things in parens. (You can give a numerical argument to the following command by doing C-u followed by a number, or by holding down Meta (probably Alt) while typing a number.) It also highlights matching parens, without which editing lisp is a nightmare.

Steve Yegge's effective emacs blog post is good, and item 4 (use incremental search for navigation) is part of why I have a hard time seeing how keybindings for up/down/left/right could matter much. Incremental search and a few s-expression navigation commands and M-f and M-b (to move forward and backward a word) can take care of the majority of your navigation needs.

The M-/ command will try to autocomplete the current thing you're typing, which is very nice for long variable/function names. There's also the C-M-% command, and yes it requires you to hold down control and alt and shift at the same time, but it lets you query-replace with regular expressions, which allows for some neat tricks.

Also, the regular cursor keys do still work in emacs (I can't tell from your post whether you noticed that or not) and there is a CUA mode that lets you use windows-style cut-and-paste if you prefer it.

share|improve this answer
add comment

I find these bindings very strange. ... What am I doing wrong?

You should find them strange, because they are, or they will be until you've taken sufficient time to get accustomed to them. If you haven't got past the tutorial, what you're doing wrong is not giving yourself time to get settled in with it before making comparisons to things that are already familiar.

Choosing an editor for long-term use is a commitment that is, in many ways, like finding someone to marry. On the first date, everything is completely unfamiliar and maybe uncomfortable. As time goes on you'll become more at ease and find the relationship to be a mixture of things you like, things you don't and things you can learn to like or at least tolerate. If the overall balance is wrong, you end it and go on to whatever's next. If it's right, you stick with it and you've got a partner for life. One thing I can guarantee is that drawing comparisons to your ex girlfriend on the first date will cause the relationship not to go well.

After a few years' daily use of vi (25-ish years ago), I started using Emacs and it's been my editor of choice since. I'm not here to extol the virtues of one over the other (or either over anything else), but I will say my first couple of weeks with both were no picnic. I needed to keep reference material handy, and my work was clunky and slower until I learned what I needed. After awhile, the situation improved and now most things I do with are so reflexive that I don't have to think about them. The same would be true for almost any tool, and the things that are most worth learning have a steeper learning curve.

So how is emacs more productive?

Your metric for productivity appears to be level of comfort with the key bindings, so the answer for Emacs and any other tool you're not using daily would be "it isn't."

My metric for productivity is how long it takes me to do the things I do often and whether or not the tool can be adapted to reduce that time.

Case in point: I frequently need to transform parts of my buffers using command-line filter programs. Emacs provides shell-command-on-region (bound to M-| by default), which gets me halfway there by running the command and putting the results in a new buffer. Using that meant I had to go through a bunch of machinations to get the text out of the new buffer and replace what I'd selected. To make myself more productive, I wrote shell-command-in-region, which is about nine lines of Emacs LISP, bound it to M-# and have used it more times than I can count.

People have written hundreds, if not thousands, of these sorts of add-ons that range from simple things like what I described to interfaces to version control systems to entire applications like the mail reader I've used on a daily basis since the late 1980s. (I do use others, but this one works great in a terminal.)

On a related note: A number of answers and comments have suggested that the key bindings in Emacs are customizable. They are, but I advise against rebinding the basics. Doing so ties you to your customizations and will leave you fumbling when you have to run Emacs on a system where you can't just dump your .emacs into place.

share|improve this answer
add comment

As other said, the keybindings are more or less mnemonics, and to understand them you have to know that the terminals on which emacs keybindings have been designed hadn't always arrows keys, and were generating only ASCII code (so CTRL-H is the same as backspace, if there was a backspace, CTRL-I as the tabulation, CTRL-J/CTRL-M as enter/return) and the CTRL key was were the CapsLock is now or next to it.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.