Monday, June 27, 2011

Emacs Pinky

Whelp, it has happened to me.  After switching to Emacs 2-3 years ago, I have finally developed a repetitive stress injury due to my programming.  I don't think this would have happened with Vim (my old editor), but I have been coding much more these days.  Whatever.

I am resistant to using Viper mode as I think it will mess with the key bindings in the 20 some odd major modes I use every day.  So I am going to try something else.  I am deleting the Ctrl and Shift modifier keys from the X key bindings on the left side of my keyboard and will force myself to use Shift and Ctrl on the right hand side for a while.  Spreading the wear out over both hands should help things a bit.  Of course things are complicated a bit by the fact that this Mac keyboard doesn't have a left control at all.  No biggie with xmodmap.  Just use xev to figure out what keys send what code and make a xmodmap input file like this.
clear control
clear mod1
clear mod4
clear shift

keycode 50 = Shift_L
keycode 62 = Shift_R
keycode 37 = Control_L
keycode 108 = Control_R
keycode 64 = Super_L
keycode 134 = Alt_R
keycode 133 = Alt_L

add shift = Shift_R
add control = Alt_R
add mod1 = Alt_L
add mod4 = Super_L
Oh yeah, if you are using Ubuntu or probably any mainstream distribution, changes to xmodmap are often times intercepted on startup and different key mapping utility is used. in short, make this file as xmodmap in your home space, apply it, then restart the X server. You will probably get a dialog asking you if you want to include these key mappings or not.

Just run xmodmap <input-file> to effect the changes.  Also, I am going to try and mimic the key placement of the older space cadet keyboards, which were made for Emacs.  The Wikipedia page states that a big difference was that the space cadet keyboards had modifier keys in a "thumbable" position.  So I am leaving my left Alt as Alt and setting my right Alt as a Ctrl.  This means that in a few weeks time I should be using thumbs for most Emacs work (and everything work, as xmodmap changes are X global).

Now, the only thing I use my left pinky for is typing and Tab, which seems fair.  I'll see if things get better.  Maybe I will end up in Viper mode.

Update: Things did get better, but just barely. I do believe that the numbness is caused primarily by just a few common Emacs commands, like C-c C-c, C-x C-s, or any command that uses the C-c or C-x prefixes. In fact, my opinion is that the left hand is way over used in Emacs. I had to re-enable the left shift key for the sake of my typing speed. This has also revealed that Apple cut a few corners when it came to their keyboard hardware (everybody does). The left and right alt keys, when pressed at the same time, will stop any keys on the "zxcv" row from even producing key codes, so that's a pain right now. As of testing just a few minutes ago, the numbness comes back with just a few minutes of typing on a normal keyboard layout.

Update (after a few months): This has basically been resolved.  A few thoughts: mapping to thumbs seemed like a good idea, but thumbs get worn out too.  After a few months, my thumbs were pretty ache-y.  In the end, the two things I found that really did make a difference were: 1. binding caps-lock as a control and 2. switching to a Dvorak layout, more specifically the Programmers Dvorak layout, which I think is pretty smart.  I can't say how much each of these contributed individually, as I changed them simultaneously.  I plan to write a post on Programmers Dvorak soon but suffice it to say, switching layouts isn't a decision to take lightly.  The caps-lock thing, on the other hand, is dead simple and helps tremendously; I very much suggest it.  I only wish I had another key right beside the caps-lock (or in the pinky position on the right hand) that I could bind to Meta/Alt.

2 comments :

  1. I also find like viper mode cumbersome, and I do like vims modular approach so I've found alternative vim-mode at http://emacswiki.org/VimMode helpful. It's hosted at bitbucket https://bitbucket.org/lyro/vim-mode and appears to be abandoned, in it's state it contains some bugs but is generally usable and you might find it helpful too. I personally use its heavily modified version and it doesn't interfere with bindings of other modes.

    There's successor to the viper and vim modes called ex mode but I don't use it since it resembles viper too closely for me.

    To solve finger pain I switched to vims modular approach to editing and dvorak keyboard. IMHO you might find it helpful to switch away from control/meta-centered keybindings to modular approach or something else. In my experience control/meta keys are to be blamed for fingers pain.

    Also I think switching control and Caps Lock won't resolve your problem completely since there's fair amount of Meta and Shift keys involved.

    ReplyDelete
    Replies
    1. I would say that the enemy here isn't just key-chords but modifiers in general. I examined where I was using modifier keys and came to the conclusion that it isn't just the key-chords, that are causing problems but general typing as well. I believe that the source of the problem is partly the key-chord style Emacs editing exacerbated by the fact that my keyboard only has a control on the left side, and partly the fact that programmers use the left shift-key way too much.

      I noticed an improvement upon switching control and capslock and that was next to zero cost due to misguided muscle memory (I, like most people never use capslock). This helped so much because most commands I use from Emacs involve the control key and only the control key. This cuts back on odd contortions of my pinky to get to that left control key. This is so low cost that I would go so far to suggest this for all Emacs-ers, and think that mapping caplock to escape for Vim users is a probably a good idea as well.

      However, I think that you are probably right that the capslock/control switch isn't enough by itself to remove all discomfort. That brings me to the Programmer Dvorak bindings. These bindings are awesome if you want to cut down on the number of shifted keystrokes you make. I use capslock (currently remapped to the Esc key) for numbers and it turns out that I very rarely have to hold shift for anything. Once again, I have cut down on the number of times that my pinky has to go through the (more mild) contortion of reaching the shift key. Now, even though I have shift keys on both sides of my keyboard, some of the most common symbols that I type while coding are '(', ')', '{', '}', '"', or '_', '>', '+', '*'. These are certainly very common in my two "favorite" languages, Lisp and C. These are usually reached with your right hand while your left holds the shift key. I'll bet that whatever language you favor you are using these symbols a lot as well and if you are on a qwerty keyboard, you are heavily favoring your left shift key.

      These two changes have basically solved any issues I had. Turns out that key-chords themselves are not enough to tear up my fingers, I need to open and close a few million parentheses and braces before the effect really got to me.

      That said, I do not recommend ordinary people switching to Dvorak or Programmer's Dvorak. For me, this took a very long time to regain my typing speed which is still only pushing 60 WPM, though improving, and have essentially forgotten all Qwerty touch typing which, naturally, became a pretty big hurdle for my job. Perhaps if I was a classically trained typist to begin with rather than self taught it would have gone easier and without as much loss of previous ability.

      Delete