reddit / emacs

Navigate to positions within long words

RepublicWorried · 2022-10-24 19:27
A typical scenario is a quite long function name, e.g. void myVeryLongFunctionNameWithoutAnyPurpose(int a); ​ what is the most efficient, built-in way to navigate to e.g. the Name subword? using subword mode still makes me press M-f multiple times and also slows down general buffer navigation by treating every capital letter now as a separate word.
timmymayes · 2022-10-24 19:59
I've been using iy-goto-char from dotian [https://github.com/doitian/iy-go-to-char](https://github.com/doitian/iy-go-to-char) I'm trying to determine if I prefer avy jumping really close to the word or just using a number modifier into a ctrl-n or ctrl-p to get to the line. I use relative line numbers so C-8 C-n H-f <char target> where H-f is my iy-goto-char key is relatively smooth.
TheFrenchPoulp · 2022-10-24 20:03
Built-in would be `isearch`
nandryshak · 2022-10-24 20:22
Perhaps [avy](https://github.com/abo-abo/avy/). I would use the command`avy-goto-char-2` then type `N a` and the corresponding jump key (if it appears). `avy-goto-subword-1` is a bit more niche but might also work well.
redguardtoo · 2022-10-25 01:14
Or use `avy-goto-word-or-subword-1`, Quote from its doc, "Forward to `avy-goto-subword-1` or `avy-goto-word-1`. Which one depends on variable `subword-mode'."
sebhoagie · 2022-10-25 02:47
Adding to this, I always thought it would be nice to "master" the jump by words/paragraphs/etc commands, and use prefix args to move "## lines down" etc. And I also found the idea of moving around using isearch a bit mmmm arcane? primitive? But lately I've been giving it a try, and I think I was completely wrong. There's something to be said for the simplicity of C-s/r and typing. You don't have to think ahead in any way (which command? how far? etc), other then start typing your target and *get there*.
arthurno1 · 2022-10-25 03:09
>what is the most efficient, built-in way to navigate to e.g. the Name subword? > using subword mode still makes me press M-f multiple times and also slows down general buffer navigation by treating every capital letter now as a separate word. Ii am not sure what do you ask for. Your title suggest that you wonder how to jump to part of names, but your question asks how to jump to the end of a name. I think built-in paredit does what you ask for. I personally use both subword and paredit mode. Paredit has paredit-forward/backward functions, which correctly jump to the end or beginning of a name regardless of subwords and to close/open parenthesis when not at a beginning of a name. Emacs can't decide on its own which one you would prefer, so you will have to use one of forward-word or paredit-forward. I personally have bound paredit-forward to C-. and I use C-, for paredit-backward (sort of , comes is to the left of . on my keyboard, so it was easy to remember for me). If you are not used to paredit-mode I suggest lookup the help for paredit, as well as some tutorial, because it might be a bit frustrating; it will change your key-bindings substantially so be sure to re-bind as it suits you and to understand how structure editing with paredit works.
00-11 · 2022-10-25 03:37
Are you just looking for `C-M-s \BName`? That finds `Name`, but not with the `N` at the beginning or end of a word. That puts it in the middle of your long word somewhere. We all like to point out that it's wrong to see regexps as a hammer and every search as a nail, but sometimes a simple regexp can do what you might think would require more.
Belaba · 2022-10-25 05:46
When you get proficent with ```avy-goto-char-2``` and ```avy-goto-line```, you'll seem like a wizard to outside people. On the flip side, you'll feel even more crippled when you have to use some other editor
mickeyp · 2022-10-25 08:42
Indeed. It's a powerful method of movement, and one I recommend in my book for that very reason, but it's best used in addition to the kill/move by X commands.
Desmodromo10 · 2022-10-25 15:51
This is where the vim normal mode keys f/F t/T really come in handy. Hail evil-mode.
RepublicWorried · 2022-10-26 12:01
can you elaborate what you mean by the last part of your sentence?
mickeyp · 2022-10-26 12:12
Sure. Isearch is useful for search and navigation, but it's not a replacement for moving by word, s-exp, paragraph, defun, etc. and their equivalent kill commands. You should endeavour to use both.
RepublicWorried · 2022-10-26 12:19
I dont have line numbers, so that is not an option good sir
RepublicWorried · 2022-10-26 12:53
thanks, you know, those classic commands like C-M-f and the likes never really worked for me since I have always been struggling to predict what they will do precisely in which context oO
timmymayes · 2022-10-26 17:48
That makes sense! Avy or Ace Jump can get you in front of the word then M-f?
RepublicWorried · 2022-10-27 05:34
Ofc. So with point at the beginning of the word above, I have to press M-f still like many times to end up before the part with Name. With subword mode disabled, point skips over the entire word. Both not ideal