reddit / emacs
Remapping navigation keys for Dvorak layout
aqjo · 2022-04-23 13:22
I’ve been reading and searching, but am not sure how to do this. As with most things Emacs, there are tons of options.
I would like to use the homerow keys hjkl (QWERTY) to navigate with my Dvorak layout keyboard, which would be htns. (My keyboard is programmed for Dvorak.).
I’m using Emacs from Scratch configuration, which uses evil mode. I see the two lines following, so perhaps I could just change them to “t” and “n”, but what about h and s?
;; Use visual line motions even outside of visual-line-mode buffers
(evil-global-set-key 'motion "j" 'evil-next-visual-line)
(evil-global-set-key 'motion "k" 'evil-previous-visual-line)
I assume everything would be different if I decide not to use evil mode? Maybe using something like and adaptation of:
(global-set-key (kbd "C-h") 'backward-kill-word)
Finally, replacing C-x (quite a reach on the Dvorak layout) with C-u (right under the left index finger) makes so much sense. Would this work?
;; swap C-x and C-u
(define-key key-translation-map [?\C-x] [?\C-u])
(define-key key-translation-map [?\C-u] [?\C-x])
And does it work with daemon mode now? (Via launchd?)
macOS 12, Emacs 28.1
Thanks 🙏
falsifian · 2022-04-23 14:59
For what it's worth, as a long time user of both vi-style keybindings and the Dvorak keyboard layout, I've found no need to remap them. I've gotten quite used to where my fingers need to go for hjkl.
Similar for C-x: it hasn't been an issue for me. I think I typically use my left hand to hold town ctrl (mapped from the caps lock key) and my right hand to press x.
Sorry for not answering your question. But I'm quite happy with my decision not to complicate my life by trying to reconfigure everything just because I'm using a different keyboard layout.
404cn · 2022-04-23 15:13
Take a look at keyboard-translate.
Extension_Try_6870 · 2022-04-23 16:03
I second this. Reconfiguring hjkl is going to get you into way too many problems. You can get used to your layout the way it is and in addition, there is more efficient way to move around than hjkl.
thetemp_ · 2022-04-23 18:01
You can really drive yourself crazy doing this, because there's a never-ending list of unintended consequences you run into. Evil-mode is already a big change from regular Emacs bindings. But at least there's a large community and ecosystem around it. When you start changing it, you start noticing that you need to tweak other areas in order to have consistency elsewhere.
> I would like to use the homerow keys hjkl (QWERTY) to navigate with my Dvorak layout keyboard, which would be htns.
IF you were to do this, I'd go with the same key locations that Vim/Evil use in QWERTY, which are "dhtn" in Dvorak ("htns" would be shifted to the right by one key). This puts your index and middle fingers on the up and down keys, your ring finger on the forward-char key, and you only have to reach your index finger over to get to the backward-char key. This avoids over-using the pinky finger and allows quickest use of the most important keys.
But I also want to caution you that when you use evil-mode but also change its bindings, you become the odd-man-out doubly so. You'll either have to change the bindings for every major mode you ever use, or you have to context-switch all the time.
> swap C-x and C-u
Again, IF you do something like this, I'd suggest a different route. "C-u" is an important key. A better key to move C-x to--if you must--would be "C-t". But there is a side benefit to having the "x" smack dab in the middle of the board. While it's not an easy location to reach in general, it is a very versatile location. You can reach it with either hand, which means you don't have to swap the hand holding Ctrl when you enter sequences like "C-x C-s" (unless you use a split keyboard of course).
Of all the alternative layouts, Dvorak has some of the least-bad bindings for Vim/evil-mode. You've got j/k right next to each other already. While you may notice that the l isn't as well-placed, *you really don't want to rely on the character movement keys too much anyway*.
Instead, use Avy. If I had to choose one package to install in Emacs, that would be it. You can get anywhere on the screen with it, and [you can do tons more](https://karthinks.com/software/avy-can-do-anything/). If you use it right, you won't care as much where the character navigation keys go.
Or, you can set up a navigation block using one of the other modifier keys.
But if you're not a Vim user already, my suggestion is to stick with Emacs bindings. Vim bindings seem attractive at first, but the more you use the standard Emacs bindings, the more you appreciate them and the more efficient you realize they are.
Also, there are other modal editing options, which IMO work better with Emacs. Since these other options aren't trying to fully simulate a different editor (Vim), they're able to avoid straying so far away from Emacs conventions. My favorite example is [Meow](https://github.com/meow-edit/meow), where if you use it's [suggested command layout for Dvorak](https://github.com/meow-edit/meow/blob/master/KEYBINDING_DVORAK.org), you won't have to context-switch when using existing special modes like ibuffer, dired, or list-packages.
Another option is [xah-fly-keys](http://xahlee.info/emacs/misc/ergoemacs_vi_mode.html), the author of which is a Dvorak user. It places bindings based on a study he and some others did of the [most frequently-used commands in Emacs](http://xahlee.info/emacs/emacs/command-frequency.html). Like Meow, it is also layout-agnostic.
I've made a ridiculous number of adjustments on my setup, but the greatest improvement I've realized for ergonomics has been the commonly-advised tweak of setting the CapsLock key to work as a Ctrl key.
Jealous_Sherbert_299 · 2022-04-23 19:45
I have been using emacs with C-x and C-u swapped for quite some time now, and it's really nice. Perhaps my most common bindings are C-x C-s and C-x C-e, which happen to be fully homerow sequences.
Many people do use vim bindings on standard dvorak, but in my opinion this is a subpar experience that you should not settle for.
I fully recommend [meow](https://github.com/meow-edit/meow) as possibly the best out of the box modal editing experience for emacs and dvorak. It'll take some learning because meow adopts a different philosophy to vim in several regards. I'd suggest looking at the suggested dvorak keybinds, and then remap what you think will be more comfortable, since meow makes this extremely trivial while also preserving consistency across other interaction modes unlike evil. If you're after some other ideas, you might be interested in my meow-dvorak [configuration](https://github.com/eshrh/nyaatouch).
aqjo · 2022-04-23 22:43
Intriguing! Thanks!
aqjo · 2022-04-23 22:51
Thanks!
Also great advice!
I've mapped CapsLock to Hyper or if tapped F18 to launch Raycast, so that would take some unlearning. Still might do it though.
Just discovered Avy yesterday, coincidentally after thinking about how much time and keystrokes are wasted moving from one place to another.
Looking forward to giving it a try!
thetemp_ · 2022-04-24 02:25
In case you haven't heard of it, [kmonad](https://github.com/kmonad/kmonad) makes it possible to do a lot of these kinds of system level adjustments.
I've actually got both CapsLock and Enter mapped as Ctrl when held down. If tapped, Enter works as Enter, and CapsLock acts as a prefix key.
whudwl · 2022-04-24 07:10
I use dvorak, but I myself do not find it necessary to re-map anything. Pressing c,v for j,k is just fine with me :)
vaxdar · 2022-04-24 15:12
I'll add a minority opinion here, I use htns and I don't find it to be a problem. I started doing this with vim when I learned dvorak around 15 or so years ago and carried it over when I switched to emacs a few years ago. A few rebinds/unbinds in `general.el` and a few translations with `evil-collection-translate-key` seem to handle it for me.
I do have to agree with others on the messiness of changing too much though. It's worth trying the defaults first and seeing if you can adapt. I know I changed a lot of things when I was starting with emacs that I thought I wanted that I ended up undoing later. I now use a mix of vim-style and emacs-style bindings, but I've stuck with the core htns setup (and haven't wanted to bother changing it, unlike other things). So far, anyway.
aqjo · 2022-04-24 17:08
Thanks!
The appeal of staying on the home row is strong to me.
Someone mentioned pinky strain by using s, but on the other hand (literally), there's caps lock/ctrl doing all that work.
aqjo · 2022-04-24 17:12
Thanks!
I've used Karabiner-Elements for pqrs.org for years, but will have a look at kmonad and see what it has to offer. I'm thinking about Programmer Dvorak, so this might give me a way to do that without reprogramming my board so much. (Also, the Drop configurator doesn't support everything QMK does (as I recall)).
thetemp_ · 2022-04-24 17:40
> I'm thinking about Programmer Dvorak
I've been using it for a couple months now actually. My only complaint is how he swapped single-quote and semicolon. Can't figure out the rationale behind that one. Other than that it's an improvement. A lot of keybindings are easier to reach since you don't have to press shift with them anymore (M-@ for mark-word, M-{ and M-} for paragraph movement, etc.).
If you use numeric arguments much, you might want to use [vertigo](https://github.com/noctuid/vertigo.el) with Programmer Dvorak. It makes it possible to set numeric arguments from the homerow. And you can do:
(customize-set-variable 'vertigo-home-row '(?u ?h ?e ?t ?o ?n ?a ?s ?i ?d))
So it matches the layout of Programmer Dvorak's number row.
vaxdar · 2022-04-24 17:58
Not moving more than necessary is nice. I base all my navigation around those right hand homerow keys (arrows on a layer, etc). Overuse of s hasn't bothered me so far (even with l on the same finger), and I've been doing it for years now. I also use a pretty small keyboard (dactyl manuform) with no outer columns for the little finger, and all mods (shift/ctrl/esc/etc) on thumb keys. Before this keyboard, I used the caps lock as control, so both little fingers were busier then.
aqjo · 2022-04-29 01:31
I’m not sure about his thinking on rearranging the symbols. He may have justified it and I’ve forgotten. I do recall he mentioned being able to type open and close brace by rolling two adjacent fingers, but then I’m like, where the heck is everything? Backtick is now on the other side of the world from tilde, etc.
I’m thinking about doing my own version and just “unshifting” the symbols on the number keys and leaving the rest where they are.
aqjo · 2022-04-29 01:36
What would you suggest as being more efficient?
It’s a little annoying there are so many different bindings in different contexts for up/down/next/previous, whereas the arrow keys always do what one would expect. Why not do that with hjkl (or something else standardized)?
aqjo · 2022-04-29 02:49
Thanks!
Kind of wish I hadn’t seen that Dactyl Manuform :-)
vaxdar · 2022-04-29 02:59
Hah, you're welcome. Good luck ;-)
thetemp_ · 2022-04-29 03:33
Hm. The only braces you can roll in that way are the curly braces. The others are on opposite hands. But it's not usually necessary, because of `electric-pair-mode`.
I think some of his choices work for some languages more than others. Like the backtick being moved across the keyboard and being replaced with the dollar sign. Doesn't make sense for someone programming in Lisp. But it would for someone using Perl.