reddit / emacs

Key Bindings: Strategy and Best Practices

schmudde · 2022-12-20 18:20
Hey-o. I'm quite happy using my standard Emacs keybindings. But when I need to assign a new key binding for a single command, I suffer from having too many options. So what are your strategies for choosing sensible keybindings? I'll start - I've found function keys to be invaluable when wanting to enter a package with its own menu. `F3` for `org-agenda` or `F8` for `deft`. It may be an obvious application of the function keys, but it was a pattern that I had to independently discover.
ieure · 2022-12-20 18:56
I dislike using function keys at all, since they're far from home row, and they usually require a Fn modifier to work on a laptop. I set up a Hyper key and put most of my bindings there, since practically nothing uses that key at all. `H-ESC` brings up a `transient` window with an application-launcher type menu.
timmymayes · 2022-12-20 22:01
I typically try to stick to the standard C-x for system wide functions C-c for most minor mode and personal bindings. However I have setup Hyper and Super to work as well and leverage those extra keys for a variety of things. I also have a Dactyl-manuform keyboard with thumb clusters which lets me easily press lots of modifiers. My 4 thumb cluster buttons are: 1. Alt 2. Hyper 3. Super 4. QMK Layer Shifts (different layer on left and right side) I am planning to do some overhaul to my config and will probably use `H-c` as a prefix key. Below are some ways I utilize Hyper atm that saves me some repeated keystrokes. I'm trying to work out a framework for `H-<key>` and `C-H-<key>` for related but expanded functions. You see that below with `H-b` quick switching the buffer and `C-H-b` opening a full screen buffer list. | action | key | |-------------------------+------------| | other-window | M-+ | | 'ace-window | M-[ | | 'treemacs-select-window | M-] | | 'treemacs | C-c s t | | 'delete-window | H-<escape> | | 'delete-other-windows | H-1 | | 'split-window-below | H-2 | | 'split-window-right | H-3 | | 'buffer-menu | C-H | | 'buffer-quick-switch | H-b | | 'list-bookmarks | C-H-g | | 'dired-jump | C-H-t | | 'kill-current-buffer | H-k |
timmymayes · 2022-12-20 22:09
I used to be that way but when I switched to my dactyl-manuform I have access to F1-F24. Though I'm not fully utilizing all of them yet. They are much easier to press now though as I have a layer shift key on both the left and right halves of my keyboards. The layer shifts do a few things but they also change my numbers to Function keys so they are easy to reach via a thumb press + normal number. I keep F1-F4 as defaults but have started using the others. So far mostly for quick keys for org-agenda views and a few hydras for things I don't often use like loading music, changing text scale etc.
0lMon · 2022-12-20 23:07
Hej Hej, I read that from someone once and now I think that is one of the better solution for custom keybindings: `C-z` is `suspend-frame`, that is something I just don't need as a keybinding. So I unbind `C-z` and use this as a prefix for my custom keybindings. That is very close to `C-x` and `C-c` so it feels natural.
ieure · 2022-12-20 23:50
Sure; my daily driver is an Ergodox, so I'm very familiar with layer switching and the like. I still find it less efficient, since the layer mods are less convenient than regular modifiers, and I use both the Ergodox and a laptop keyboard.
schmudde · 2022-12-20 23:51
Ah `C-z` is a clever tip. That might be the way to go.
schmudde · 2022-12-20 23:54
I may not use the Hyper modifier, but I like some of these keybinding ideas. Thanks.
timmymayes · 2022-12-21 01:04
That makes sense. This is why I tend to use them for things I'm not using during editing. Popping open my agenda for example. I've even gone so far as to use the layer switch key to add F3 and F4 to the keys under my x & c keys so that I can make and use macros a bit easier. I started with the Ergodox infinity actually and when it broke (taking to and from work the usb-c cable suffered unplug/replug wobble, I decided to 3d print and hand make a dactyl. It was so great.
ieure · 2022-12-21 01:40
Dactyl looks so bad-ass. I'm onto the SliceMK Wireless Ergodox these days, but my first (which I still have & occasionally use) was a Massdrop GB which I had to completely assemble. Over 300 solder joints. Good stuff.
timmymayes · 2022-12-21 01:59
Nice! I want to make a wireless one next. Gonna try customizing the design so the outer bottom keys which I use for control are 1.5 keycap size since I palm press and that tad extra big key would be nice.
your_sweetpea · 2022-12-21 02:21
Truthfully, 99.99% of the time I simply use `M-x command RET` over anything else. When pushed though, I tend to stick with the C-x for global bindings and C-c for local bindings pattern. I kind of want to work in some sort of leader-key system with SPC like you see in Doom and Spacemacs, but that requires me to finally commit to switching to [meow](https://github.com/meow-edit/meow), which I just haven't set aside a weekend to get comfortable with yet.
thetemp_ · 2022-12-21 06:49
I've experimented with different keybindings a ton in the past year or so. But I find myself being drawn back toward the defaults for the most part. Still, I have a few customizations that I'll probably never let go of. C-t :: Since I use a flavor of the Dvorak layout, I like having C-t bound to simulate a C-x keypress. I could bind it to `ctl-x-map`, but some modes (e.g. `org-mode`) set bindings under C-x within their own keymap, so simulating the keypress captures those bindings as well. If you use key-translation, then every C-t in every key sequence becomes C-x, which I don't really want. Another benefit of this is it gives me a way to press C-x on either side of the keyboard. So to `eval-last-sexp` I press C-x C-e, but to `switch-buffer` (actually `consult-buffer`), it's C-t b. This avoids having to press different Ctrl keys in the same key sequence. To find a new home for `transpose-chars` (formerly residing at C-t), I've tried a few different options (like binding it in `isearch-mode-map` and doing C-r C-t). So far, the simplest way has been using C-c c. C-h :: I have a key-translation for C-h so it acts as backspace (to match the Bash/Readline binding). That one's less problematic than translating C-t, because C-h does the same thing in every key sequence. So there are no unexpected surprises. I've gotten used to just pressing C-S-h for `help-map` bindings. And I might also have that set as the `help-char`. (Can't remember if I had to do that at the moment.) F1 is another potential alternative. C-w :: Also to match Bash/Readline, I have this bound to a command that runs `backward-kill-word` if the region is inactive, and the normal `kill-region` if it is. C-c :: Numerous prefixes and such bound to letters in `mode-specific-map` (C-c), including one for the `windmove` commands, which I quite like. This is the convention, and for custom bindings it covers just about everything I need. Recently, I got one of those keyboards that has a column of macro keys on the left-hand side. So I set up one of them to issue C-x o (`other-window`). Not sure how I got by without this before. M-o is a pretty good binding for it, but having just a single key to press for switching windows is really nice.
Ill_Pause3020 · 2022-12-21 10:27
Since you like the Emacs way, the recommended way is to use "C-c <letter>" (upper or lower case); anything else is sorta up for grabs by major modes and other things. The Function keys from F5 to F9 are for users specifically, e.g., F3 is normally bound to kmacro-start-macro-or-insert-counter ... and Emacs might take over that from you when you least expect it :-) A good chapter on this is https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html Some nonsense that I have in my .emacs: ``` (global-set-key (kbd "C-c c") 'calendar) (global-set-key (kbd "C-c d") 'diary) (global-set-key (kbd "C-c s") 'slime-selector) (global-set-key (kbd "C-c a") 'org-agenda) ```
Gallipo · 2022-12-21 15:14
I use a similar approach, but with `M-SPC` as prefix. By default it is bound to `just-one-space` which I shifted to `M-SPC SPC`
luiggi_oasis · 2022-12-21 16:38
Is hyper= "windows" key? If so, I call it muscle and I left it exclusively for i3 bindings.
ieure · 2022-12-21 16:53
No, that's the Super modifier. X11 and Emacs both support a lot more modifiers than are generally used: - Meta - Alt - Control - Super - Hyper I believe that Alt, Super, and Hyper were inherited from the early Lisp machines. Nearly nothing uses them, so if you can wrangle the X config, they're great places to put new bindings.