Thursday, January 17, 2008

Our new Emacs overlords?

As programmers, we should fret over our tools. Well, I don't know about everyone else, but I fret over my tools. This leads me to spend time learning tools that would cause normal people, even normal programmers, to shy away.

I'm a programmer of many languages, so I find IDE's, while helpful sometimes, are not something I can universally rely upon. For instance, I've yet to see a C development environment that is more productive than VIM and GCC on Linux, and this is not for want of looking. When I use more esoteric languages, it's often that the closest thing to editor support I'm going to get is some syntax highlighting in VIM and Emacs.

When I was a teenager being first exposed to the world of Linux, for some reason (I really don't remember why), I learned VIM first. I got pretty good at it. I could use VIM to produce C code like nobodies business. I find VIM the optimal editor for Perl coding. I have several hundred VIM shortcuts memorized. In QWERTY. In Dvorak, I know something like 20 VIM commands.

This is a problem. I've spent the last year hobbled in my VIM usage. I feel like a complete novice. I'm not even sure exactly what key to press to yank without looking at the keyboard. Advanced editing is way out of the question. It's as if I've been using the big blade on a Swiss army knife to cut cheese, leaving the other blades untouched and unused.

This is obviously not optimal. While I still beat out most other editors (except the all-mighty Eclipse/Java pair), I know my efficiency has been hurt. I know my code is suffering. I don't even try to do LaTeX in VIM anymore. So it's time for me to re-evaluate my tools.

I tried learning VIM for Dvorak. I really did. I spent a few hours running command practice. I printed a cheat sheet optimized for my Dvorak troubles. I've stuck with it for a year, hoping that I'd learn the keys by repetition the same way I did the first time. No such luck. Dvorak + VIM is an illogical beast of several hundred irrational keys to memorize. There's no core logic to the keyboard layout that justifies the common choices, and none of the keys make sense. To make matters worse, I still haven't gotten the bottom row of Dvorak imprinted into muscle-memory so I miskey unless I'm typing a word. This simply isn't working.

Which leads me to Emacs. I decided years ago that "some day" I would learn Emacs. Of course, picking up Emacs as a skilled VIM user is not really an easy task. It's about as hard as a skilled QWERTY typist switching to Dvorak. In the beginning, you spend absurd amounts of time looking up basic commands, killing your efficiency. I'm fairly certain, if I hadn't made the switch to Dvorak, I'd never get to the Emacs switch. It's a big investment, and I'm putting my time in to become proficient. I've been using Emacs extensively for three days now and I'm starting to get the basics by route. It's definitely feeling more Dvorak-friendly than VIM ever did (though that could be because I had experience with Vim in QWERTY). And overall, I'm pretty happy with the switch.

Which brings me to the point of this post. Everyone with a keyboard made in the last 3-5 years has noticed (or not) a little button on the right side that's allegedly a "menu" button. Allegedly. On occasion I've accidentally pressed it and weird things have happened, usually context menus. It's always been a mystery to me how this button made it onto keyboards, as it's clearly the most useless button ever. That is until I started learning Emacs, when I realized it's a shortcut for M-x. I think this is clear proof that there is a vast Emacs using keyboard conspiracy out there, and we should probably start protesting the Emacs-illuminate.

PS: If you read this, and you are still using QWERTY, you should hop back up to the first paragraph. The only keys that I'm not happy about in Dvorak are {}, but even that is pretty easy for me to deal with (not that I voluntarily use a curly-bracket languages any more). In all other ways Dvorak is vastly superior, and I've never heard a good argument not to use it other than "I don't feel like learning it."



violagirl23 said...

There is a solution! You can add but one line to your .vimrc file to make it so when you are in input mode you use Dvorak, but when you are in command mode all of your shortcuts still use the qwerty layout... it works wonderfully and all the hundreds of shortcuts you knew will now still apply! The only exception I have found is typing commands in command mode, after the colon. The colon is placed where it is in QWERTY, but once you get to the command part, like :w, the colon is qwerty, but the w is dvorak, because you are actually typing text to the screen. But this too makes sense if you think about it.
Just give it a try! Just add the following code to your .vimrc (and make sure it's one line! When I pasted it in it split it up into three and I had to make it one line again)
Also, I made it two lines because I had a < followed by w and the blog claimed this was html and wouldn't let me post it... just make sure you make it one line again when/if you paste it into your .vimrc

set langmap='q,\,w,.e,pr,yt,fy,gu,ci,ro,lp,/[,=],os,ed,uf,ig,dh,hj,tk,nl,-',qx,jc,kv,xb,bn,mm,w\,,v.,z/,[-,]=,\"Q,<

I have only noticed two real "side effects"-If you are actually IN qwerty and using vim, now NOTHING will work right--you actually must be IN dvorak to use your commands qwerty-style now. This is no problem for one who has sworn off qwerty altogether, though! Also, right-clicking and selecting any of the text options in gvim no longer seems to work, I used to use it to copy text when I wanted to paste it somewhere out of vim, as the v select text y method didn't ever seem to allow me to paste to a document out of vim.
But otherwise, I think it's WELL worth it and I suggest you at least just give it a shot. If you dislike it, just remove the line from your .vimrc. I love it, personally. It lets me still use vim even if I'm using dvorak.

violagirl23 said...
This comment has been removed by the author.
violagirl23 said...

It keeps cutting off my command!
Vim Tips
This is the URL that contains the command, it's the one in the first comment under Additional Notes, not the original post.

PragmaTechie said...

I can't thank you enough for this post. I'm also a Dvorak user and am deciding between Emacs and Vim.

Violagirl23's comment is also very informative.