I am a C++ dev. I am now able to follow up symbols or files using LSP,/projectile/ivy/transient aso… but inside one file, I have difficulties going quickly up function by function, or by if/for statement. Do you know a convenient way to do this ? I am interested in any navigation tips as well ! Thanks for your help !

2 points

You can go to the next/previous function with C-M-a and C-M-e. With evil mode it’s ] m and [ m. You can use imenu. You can make keybindings to scroll forwards/backwards several lines at a time.

permalink
report
reply
1 point

That one is great !!! What if I want to navigate through statements of the same type ? Like if instructions?

permalink
report
parent
reply
1 point

I’m not sure what that means, but forward-sexp, backward-sexp, and backward-up-list are good for navigating across and within balanced expressions.

permalink
report
parent
reply
1 point

I don’t know any good way to do that.

permalink
report
parent
reply
1 point

See my reply above. You can use either thing-cmd.el or find-where.el for that. You just need to define “statements of a given type” as a THING or define a predicate that is true for them. Or if their text has some property (even just face from font-locking) then isearch-prop.el will help.

permalink
report
parent
reply
1 point

Feels like this would be something cool to add to a treesitter mode.

Meanwhile I just C-s if

permalink
report
parent
reply
1 point

I like imenu-list a lot for showing the classes, methods, functions, etc in the file in a side buffer.

permalink
report
reply
1 point

I think the “hide-show” package is invaluable in navigating large files. You can see all functions collapsed in a file. Or, within a function, you can see all blocks of code {} collapsed.

permalink
report
reply
1 point

avy is good for quickly jumping between what’s visible. Occur is brilliant, it might also be worth mentioning consult and embark.

permalink
report
reply
1 point

Using treesitter you can have text objects that are if statements or functions or whatever. From there it is just a key binding away

permalink
report
reply

Emacs

!emacs@communick.news

Create post

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

  • Windows
  • Mac OS X
  • GNU/Linux and BSD (Just get it from your distribution’s package manager)

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for “emacs” and “vi” link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

Community stats

  • 18

    Monthly active users

  • 562

    Posts

  • 2.4K

    Comments