Smart Heading Navigation with Context-Aware Shortcuts for Obsidian

Use Case & Problem

Markdown documents utilize six heading levels (H1-H6). Currently, Obsidian lacks efficient navigation tools for long documents, making it difficult to:

• Quickly count H3 subheadings under an H2 section

• Preview nested heading content without manual scrolling

Proposed Solution
Implement intelligent keyboard shortcuts with document-aware behavior:

For H1 Headings:

  1. First press of Ctrl+Alt+1:
    • Collapses all H1 content (independent of current state)
  2. With cursor on an H1 heading:
    • Second press expands all content
    • Viewport automatically jumps to the selected H1 line

For H2 Headings:

  1. First press of Ctrl+Alt+2:
    • Expands all H1 headings
    • Collapses all H2 content
  2. With cursor on an H2 heading:
    • Second press expands all content
    • Viewport centers on the chosen H2 line

Consistent Behavior:

  • Extends through Ctrl+Alt+3 to Ctrl+Alt+6 (H3-H6)
  • Maintains context by tracking cursor position
  • Smart viewport adjustments prevent disorientation

Key Innovations:
• Two-phase operation: collapse overview → precise expansion
• Position-aware viewport handling
• Complete hierarchy support (H1-H6)
• Muscle-memory friendly shortcuts

This article has been translated and polished by AI

There are two related commands:

  1. Fold more which collapses current heading
  2. Fold less which expands current heading

Also there are these commands:

  1. Fold all headings and lists
  2. Unfold all headings and lists

 

You can use macros in QuickAdd to combine two actions into on action such as fold all with expand current.

Macros

Macros are the most powerful feature in QuickAdd, allowing you to chain together multiple operations into automated workflows. Think of macros as custom scripts that can execute any sequence of Obsidian commands, user scripts, AI commands, and more.

https://quickadd.obsidian.guide/docs/Choices/MacroChoice