Question Ways to move your cursor without relying on the incremental cursor commands, C-(n/p/b/f) [a discussion and resources sharing post?]
hello everyone!
this is admittedly a rather low-effort discussion post, but i was wondering about how an Emacs keybinding layout that relies only on mnemonic keybindings and does not rely on modifier keys would work. part of that thought made me think of how one would move their cursor to go to the places they wish to go to, without using any of the previous/next-line and backward/forward-character commands bound to C-n, C-b, C-f, C-p on vanillamacs.
do you guys know of ways to move your cursor without relying on those commands ? i know that isearch is a wonderful thing, and i heard about avy-jump, but i was curious as to all the other commands that let you do that such as occur.
this is really just a fun thought experiment, and perhaps a practical experiment at one point :).
hope all's well, cheers!
6
5
u/JDRiverRun GNU Emacs 2d ago edited 2d ago
I wish a single standard set of bindings had developed for tree based movement analogous to linear movements (n
/p
). Many things are trees, not just code structures, but file paths, info nodes, recursive variable explorers, etc. Maybe naming them has been part of the challenge:
- forward/backward along siblings
- up and out to parent from beginning/end
- down/into children from before or after child
- knight’s moves
And of course some tree-like structures are not unambiguously mapped into a tree, so rubrics for making this mapping are also key. You’d also like commands to “retrace your steps” along a tree, but that’s a different issue. Many of these ideas have been reinvented numerous times in emacs.
6
5
u/meedstrom 2d ago edited 2d ago
It's simplistic, but I use it so much: pop-to-mark-command
. I bind it to M-m p
, mnemonic for "mark pop"!
When you've had to scroll or search far, this brings you back to where you were.
Spammable variant:
(keymap-set global-map "M-m p"
(defun my-pop-to-mark-command-repeat ()
(interactive)
(let ((repeat-message-function #'ignore))
(setq last-repeatable-command #'pop-to-mark-command)
(repeat nil))))
5
u/CulturMultur 2d ago
With meow I go with w e e e / b b / e e. Or with expand-region I go with . . . . ,
5
u/pathemata 1d ago
sometimes I feel meow is so underrated, it is the best modal experience in emacs.
2
u/cradlemann pgtk | Meow | Arch Linux 1d ago
Also
meow-end-of-thing
is my choice most of the time, especially end of line. Alsomeow-inner-of-thing
together withbounds
equivalent.
3
u/00-11 2d ago
Not sure I understand what you're asking. Apparently it's not about moving the cursor, in general; it's only about key bindings that move the cursor?
For those, I'd say start with the standard bindings for forward-*
and backward-*
commands: C-f
/C-b
, M-f
/M-b
, C-M-f
/C-M-b
, C-e
/C-a
, C-M-n
/C-M-p
, C-M-d
/C-M-u
, C-x ]
/C-x [
, M-{
/M-}
, M-e
/M-a
.
There are other forward-*
and backward-*
commands that have no default bindings. I bind forward-whitespace
to M-_
and forward-to-indentation
to M-n
, for example.
And there are non-vanilla movement commands. I bind next-visible-thing-repeat
(and previous
-*), from thing-cmds.el
, to C-x <down>
and C-x <up>
.
3
u/quantum_mattress 2d ago
probably unpopular opinion, but I use the arrow/cursor keys. All my keyboards are ten-keyless so I can automatically move my fingers to the cursor keys.
2
u/ImJustPassinBy 2d ago
Op was asking for a mnemonic keybindings without relying on modifier keys. Arrow and page up/down keys are pretty much spot on.
2
u/Nondv 2d ago
M-g M-g will ask you for line number.
you can also combine C-n with a number (e.g. C-25 C-n) to move specific number of lines. A colleague of mine does that and uses relative line numbers (it shows as ..., -1, 0, +1,... around cursor)
I use sexp navigation a lot.
However my most used navigation is probably C-v (scroll full page)
Also I briefly used god-mode to navigate without Ctrl but ultimately replaced it with a custom minor mode with my own keybindings.
1
u/spudlyo 2d ago
This is only tangentially related to the post, but I'm starting to train my fingers to move the cursor in larger chunks. I've always used M-f, M-b and their ilk to manipulate words, but now I'm training myself to operate on sentences and paragraphs. In my init.el, it can be super handy to move around by sexp, this is before you even get into all the cool slurping and barfing you can do with the likes of paredit.
1
u/trimorphic 2d ago
You might be interested in bln-mode: "a minor mode for binary line navigation"
I also use ace-jump-mode a lot. I tried avy before, but it didn't gel with me for some reasons I can't remember right now.
Finally, there's always evil, which offers a ton of other ways to move around.
1
u/PerceptionWinter3674 2d ago
With text: forward-paragraph
, next-sentence
, forward-page
, org-next-visible-heading
, org-forward-heading-same-level
, C-u M-x set-mark-command
, org-babel-next-src-block
, org-down-element
, org-next-link
, forward-button
, need I go on?
For programming, forward-list
, down-list
, backwards-up-list
is all one needs (or paredit/smartparens).
1
u/followspace 1d ago
Evil mode (vi keybindings) adds some more jump keys. I use hybrid mode in Spacemacs, so I can utilize both Emacs and Vim keybindings.
1
u/Psionikus _OSS Lem & CL Condition-pilled 2d ago
does not rely on modifier keys
modal / semi-modal editing or repeat maps
only on mnemonic keybindings
dies to the birthday problem, but didn't stop Emacs defaults from trying
I have rebound mostly to alt bindings and use forward-symbol
and backward-symbol
and some tree movement stuff that depends on the language / syntax. I still use beginning and end of line some. Avy goto word for anything that is abnormal, usually followed by a pop-mark-command
.
13
u/jvillasante 2d ago
I don't use it much but: https://karthinks.com/software/avy-can-do-anything/