JDRiverRun · 2022-06-28 20:38
It's great that `C-n`/`C-p` (`n`/`p`) are "standard" bindings for moving up and down lines/lists/etc. across many modes. But there are many situations where you aren't navigating a flat list, but rather a "tree" of information, with more than one depth level. E.g. code (lispy and friends, many programming modes, tree-sitter structural editing), collapsable sections (e.g. magit), nested outlines (org), heading outlines (outshine), etc. Here, the different modes all seem to define different navigation commands and bindings.
It would be wonderful if there were a set of "standard" bindings for tree-movement:
* among siblings at the same level (`j`,`k` in lispy; `b`, `f` with org-speed commands)
* up a level forward/backward (`h`,`l` in lispy; `u` with org-speed)
* to the next/previous thing in the tree regardless of level (`f` from either "side" of an sexp in lispy, `p`, `n` with org speed commands).
Probably too late to find any common set of keys that would work across existing modes, but it would still be nice to have a consistent set going forward. Opinions? Anyone find the same mismatch and come up with a workable solution?
BetterEventually · 2022-06-28 23:49
Possibly poor consolation but I've always found the standard emacs bindings to be strong motivation for coming up with my own.
On the positive side, the ease of doing so is emacs' major strength.
hungry_m8 · 2022-06-29 00:01
it shouldn't take much to set ur own keybindings. I don't use the default keybindings for most packages.
org uses C-c + C-{n¦p¦f|b|u} to navigate between headlines. I use something similar in other modes.
SasukeUchiha231 · 2022-06-29 04:08
Take a look at [tree-edit](https://www.joyk.com/dig/detail/1637242389457171), It does exactly what you're asking for but only for java and python at the moment, although you can add support for other modes. There's also evil-text-obj-tree-sitter, but for evil only
karthink · 2022-06-29 05:57
There are two candidates for this built into Emacs. Neither works universally. `outline-minor-mode` keys and sexp/defun keys. For each major-mode, the former needs a regexp to find headings and the latter needs custom code.
Outline minor mouse uses an unwieldy prefix `C-c @`, but with Emacs' `repeat-mode` turned on this isn't an issue. Calling any outline command makes the keymap available with single key presses. These are exactly the org-speed-command keys. I usually bind these under `C-c` instead of `C-c @` when possible.
The sexp-based commands are bound to `C-M-*`:
> among siblings at the same level (`j`,`k` in lispy; `b`, `f` with org-speed commands)
With `C-M-a`, `C-M-e`
* up a level forward/backward (`h`,`l` in lispy; `u` with org-speed)
Up and down with `C-M-u`, `C-M-d`
* to the next/previous thing in the tree regardless of level (`f` from either "side" of an sexp in lispy, `p`, `n` with org speed commands).
With `C-M-f` and `C-M-b`.
_viz_ · 2022-06-29 08:33
I also find C-M-n and C-M-p useful. For outline-minor-mode prefix issue, I have outline-minor-mode-prefix set to C-z since I still find the prefix annoying despite having repeat-mode enabled.
JDRiverRun · 2022-06-29 18:47
Thanks. I had formerly used `C-M-a` and friends before getting into lispy. I wasn't totally clear about this, but in the perfect world there would be standard keys that could work either in 'quick keys' mode (ala lispy, org-quick, etc.) or with full key chord including a prefix.
JDRiverRun · 2022-06-29 18:49
Right, the issue is finding common keybindings that are short and work across many different modes which present tree-like data. Probably my initial request could be rephrased as "I wish 30 years ago somebody had done for left/right/up/down tree movement what somebody did for `n/p` next/previous: made it a standard" :/. But going forward it would also be nice to have a consistent set.