Help save my wrists from RSI!
March 5, 2008 11:11 AM   Subscribe

I want to learn the emacs keybindings, mainly for moving around in a block of code, and selecting text. What's the best way to do this?

I essentially type all day. A good portion of that time is spent programming (probably 6 hours a day averaged over a week). Recently, my wrists started bothering me. A few days of rest from typing, an ergonomic keyboard, and AntiRSI fixed it (as in, it doesn't hurt anymore), although I plan to be more careful about it from now on.

I think much of the problem is caused by the way I navigate through code though. I use my mouse much too often. I edit code much more often than I write new code, but I haven't learned the keybindings for moving around and selecting text, so I mainly use the mouse.

I work in Mac OS, mainly in XCode or Textmate, and I have my system set up to use the Emacs keybindings for navigation. I even wrote a little chart of the keybindings and taped it to my monitor. The problem is that it's still much easier to use my mouse (especially for operations that are like: copy this line of code over here, and change the name of the first argument to this).

Also, I find selection to be difficult to figure out. I don't understand how to get the selection I want (and this is a large part of why I don't use the keybindings), so I just don't use it, because I get much better results with the mouse.

How do I overcome this barrier and actually learn the keybindings well enough to use it over the mouse?

It would be ideal if I could learn them in my day-to-day typing, but if you have a method that requires me to sit down for a few hours and just learn them, I could give that a try too.

Thanks!
posted by jasminerain to Computers & Internet (10 answers total) 4 users marked this as a favorite
 
Emacs is not the editor to use to avoid RSI, seriously.

Actually, if you're using the GUI tools, why not use the default Apple selection bindings? They're easy to understand:
Arrow keys = move char by char
Option+left/right arrow = move unit by unit (eg word)
option+up/down arrow = move to start/end
Apple+ left/right arrow = Move to start/end of line

If you want to make a selection from your starting point, just add shift.

Much more comfortable than CTRL-laden zaniness. It's the pinky key! Ugh.
posted by bonaldi at 11:20 AM on March 5, 2008


Doesn't emacs have a hands-on tutorial built right in? C-h, t if I remember correctly. It's been a while.
posted by ctmf at 11:28 AM on March 5, 2008


The answer is not easy because learning Emacs is hard enough without having to overcome the temptation to use another tool. Disciplining yourself to not use the mouse is something only you can do.

That said, if your application supports bindings to move through text a "page" at a time, to mark a region and copy it to the kill ring, to move single characters back and forward through text, and to move the point to the start and end of a line, and do cut and paste with the region you have marked, you have much of what you need for code browsing and editing.

With that said, and assuming your Emacs emulation treats the Apple key (Command key?) as what Emacs calls "Meta", I think you need to practice with:

Ctrl-v to page upward ("scroll-up")
Command-v to page down
Ctrl-a to go to the start of the line the cursor is in
Ctrl-e to go to the end of the line
Ctrl-f to move one character forward in the line
Command-f to move one word forward in the line
Ctrl-b to move one character backwards in the line
Command-b to move one word backwards in the line
Ctrl-SPACE to mark the beginning of a region you want to copy or select
Command-w to save the text from the mark to the current point in the kill ring
Ctrl-w to cut that same region of text
Ctrl-y to paste that copied text somewhere else

That'll get you going, and is a small set to learn.
posted by galaksit at 11:37 AM on March 5, 2008


P.S. It's said that Richard Stallman, the original developer of GNU Emacs, has RSI.

I've been using Emacs daily (well, M-F anyway) for 15 years and don't have any problems.
posted by galaksit at 11:45 AM on March 5, 2008


Best answer: I think in the end this comes down to muscle memory, so you will simply have to force yourself to suppress your reach for the mouse and use the keyboard only for a few days, even though the mouse is easier. (Tape a bell to your mouse or something?) You might like this reference card, depending on how comprehensive what you have already written out is. I have this printed out and taped on the wall behind my desk.

I don't know how the emacs keybindings work in XCode/Textmate, but real (x)emacs has something called "transient mark mode", where there is only a mark right when you set one (C-space), and when a mark is set the selected region is visually highlighted. This matches up a bit more to the way conventional selection works (and incidentally, is what (x)emacs uses when you use the mouse to select something). So if XCode/Textmate can emulate this, you might try turning it on.

(Honestly, I'm not sure you'll gain any real benefits in the end by preferring emacs bindings over e.g. textmate bindings, and I say this as someone who uses emacs for almost all editing. But I've ended up concluding at some point that keybindings from program A are typically a bad fit for program B, even if B has a good emulation mode. This is especially true when program A's roots are 20 years earlier than program B, a completely different era computer-wise.)
posted by advil at 11:58 AM on March 5, 2008


The last thing I want to do is to turn this thread into a vi vs. emacs debate, but I'd argue that you should use vi if you have RSI/carpal tunnel.

I suggest this because the navigation keys on vi are 'hjkl' (the right hand's home row), and the single-key commands append/delete/undo/insert/replace/jump-words are, at most, a single row away. (a/x/u/i/r/w, respectively.) This really beats reaching out to hit the backspace or ctrl keys. Cut-and-paste is also done without any of the modifier keys, which is excellent.

This all means that you can leave your hands on the home row, and use a small range of letters (and not modifier keys) to execute functions -- which means less reaching out with fingers, less switching between the letters and the arrow keys and therefore less hand/wrist stress. Again, I have nothing against emacs - it has its strengths - but the reason I started using vi was to reduce stress on my wrists.
posted by suedehead at 12:56 PM on March 5, 2008


Best answer: I once ran a survey amongst the members of my department. Users of Emacs had significantly higher incidence of wrist problems, followed by users of VI. Users of editors with standard key bindings, such as those of Visual Studio, fared best, although they did have problems as well.

There is a cause versus correlation problem in such a study. Perhaps the more intense users of keyboards gravitate towards the more challenging editors, and their attitude affects their wrist health more than the editor itself.

However, once you understand the mechanics of wrists, and the motions that lead to damage, it seems that Emacs is the very worst thing you could do your wrists.

There is very little space in a wrist. The nerves, the tendons, the muscles and the blood vessels have to squeeze together through between a constellation small moving bones. There is friction, tension, stretching and occasionally microfractures form in the soft tissue. Normal functioning of the wrist breaks when the damage done during the day is greater than what heals overnight. Damage accumulates and eventually grows into RSI.

Open your hand and lay it softly on the keyboard. This is your hand's neutral position. Medical research shows that any deviation of more than 5° away from neutral, in any direction, starts to stretch the soft tissue in such a way that it increases the rate of microfractures. The greater the deviation the greater the effect.

To be honest, the research is young and tentative. Soft tissue is difficult to probe directly -- it doesn't appear on x-ray and there is little internal structure visible on a MRI. Instead medical research relies on indirect indicators of damage, such as a behavior where the small muscles responsible for the motion of the fingers begin to duty-cycle, taking on a part of the load of their neighbor in an attempt to relieve them for a few seconds and avoid some damage.

Nevertheless, it suggest a rule, that you should minimize the number of motions that bring your hand or your fingers beyond 5° of neutral.

Emacs, with its many shortcuts that seem inspired from circus contortionists, stands squarely against that rule. Escape-meta-alt-control-shift indeed.

This is the reflection that led me to the creation of DivaScheme, an editor whose shortcuts are entirely unchorded.

It is also the rule that went into design of the Kinesis ergonomic keyboard.
posted by gmarceau at 1:36 PM on March 5, 2008 [1 favorite]


Response by poster: Hmm okay, so emacs keybindings aren't a good idea. I'll see if I can try Vi keybindings with Xcode... it looks like it's possible. So the question is still, how do I make myself learn the keybindings?

Thanks for the advice so far!
posted by jasminerain at 5:06 PM on March 5, 2008


I just want to note a couple things that might make you consider emacs. First, OS X Cocoa widgets use emacs bindings for basic editing. You can do things like Control-k, control-y (C-y C-k in emacs speak) in other programs to cut and paste. It will help you avoid using the mouse in other programs if you learn basic emacs keys

Second, vi is a modal editor, so there may not be a way to map something like "delete-line" to a control key combination. I think it's "dd" in vi. But you have to hit escape in vi first.

If you do want to consider emacs, I would recommend mastering only a few commands first that will get you a lot of milage:

C-a : cursor to beginning of line
C-k : delete to end of line, or if at end of line, delete the CR/LF
M-d : delete word
C-y : paste (from the "yank" buffer)
C-s : search

Everything you delete by a function like this gets automatically copied, so you can paste it. For instance, if you hit M-d a few times to delete a few words, you can hit C-y once to paste all the words (as long as you don't do anything else in between).

In this way, I end up using search most the time for nagivation. When I want to move text, I just delete it line by line (or word by word), pasting it back immediately if I want to copy instead, and then pasting it where I want to move it to. I think it's faster without dealing with marking regions at all.
posted by cotterpin at 5:50 AM on March 6, 2008


Yay! vi vs. emacs war. I don't know about IDEs and their interfaces. But if you're not already an EMACS wenie and use it for mail and news and everything else, and you have RSI problems, go 'vi' (or now 'vim').

Steep learning curve, every key on your keyboard does something Get used to the modal interface. Then love the parsimony of keystrokes... "1G4ddGp" moves the first four lines of your file to the end, "uu" will undo the paste and cut and put things back like they were.

Try it, you'll like it... later you'll be laughing at emacs people for their finger contortions. :)
posted by zengargoyle at 1:52 PM on March 6, 2008


« Older Now, where have I seen that before?   |   WP image submit with captcha? Newer »
This thread is closed to new comments.