Commands to navigate between foldables

Use case or problem

I would like commands and hotkeys to quickly navigate between the different “foldable structures” in a file. When I say foldable structures, I really mean headers and lists (unsure if any other structures can be folded), with the down arrow, where clicking the down arrow results in the content being folded.

Proposed solution

I propose that the following 3 VSCode commands to be implement in Obsidian:

  1. “command”: “editor.gotoNextFold”
    • navigates the cursor to the next foldable structure in the current hierarchy
  2. “command”: “editor.gotoPreviousFold”
    • navigates the cursor to the previous foldable structure in the current hierarchy
  3. “command”: “editor.gotoParentFold”
    • navigates the cursor to the parent foldable from where the cursor is at

Example

With the following MD content:

# Parent Header

- L1 list 1
    - L2 list 1
        - L3 list 1
        - L3 list 2
    - L2 list 2
    - L2 list 3
        - L3 list 3
- L1 list 2
  • From “L1 list 1”, using gotoNextFold will bring the cursor to “L1 list 2”
  • From “L2 list 1”, using gotoNextFold will bring the cursor to “L2 list 3”
    • “L2 list 2” is not foldable, so go to “L2 list 3” instead
  • From “L3 list 1”, using gotoNextFold will do nothing since “L3 list 2” is not foldable
  • From “L3 list 2”, using gotoParentFold will bring the cursor to “L2 list 1”
  • From “L2 list 1”, using gotoParentFold will bring the cursor to “L1 list 1”
  • From “L1 list 1”, using gotoParentFold will bring the cursor to “Parent Header”
3 Likes

This would really make navigation easier. Also, used in conjunction with the “Toggle fold on current line” hotkey, these suggested commands would make it much easier to adjust the folding of a note.

I could also see a setup where there were separate hotkeys for heading and list navigation. For example, if you were on a line of a list within a heading and you used the “Go to previous fold - heading” command hotkey, the cursor would go to the heading.

Another consideration might be about whether the commands respect the current fold state. This would mean that, when this option was toggled on via hotkey, using these navigation hotkeys would only go to currently unfolded lines.

Thanks!

1 Like