Enable Vim Bindings to Pass Over Folded Sections

Use case or problem

I want to take advantage of folding more often to help navigate my notes and focus on certain parts. I exclusively use Vim emulation and Live Preview in Obsidian, and while this works well for the most part with just a couple quirks (see Go To Link Command Inconsistencies with Cursor Position, Live Preview, and Vim Mode), one quirk prevents folds from being very useful to me.

Most commonly when I am navigating my note, I use { and }. These keys jump from one blank line to the next or previous, jumping over entire blocks at a time. My hope is that I could use this to jump over the heading of a folded section. However, the Vim navigation has no “awareness” of the fold, and will jump to the next blank line inside the folded section, automatically expanding the entire thing.

Proposed solution

Moving the cursor with Vim should not automatically expand the section. If I want to expand, I will explicitly click the fold arrow, or use the unfold hotkey.

Additionally, Vim bindings should have some “awareness” of the sections that are folded, treating them like a single line. Moving the cursor up and down should go onto the heading line and past it without unfolding. Using the { and } should jump over the heading line with no regard for the content that is inside the folded section.

Another handy use case is when I put my cursor on the folded heading, and I want to add one below. So I press o to open a line below, but this unfolds the section and inserts the line directly below the heading.

Current workaround (optional)

Current workaround is to avoid using folds entirely, to use the mouse to click on the “other side” of a fold (which is antithetical to using Vim bindings in the first place), or to use some Vim motion that is guaranteed to not enter the folded section (eg. going directly to a line number on the other side, which is not practical).

I simply don’t use folds because they can’t be effective to me with this behavior.

  • At this point, it’s an issue.
  • You should go to github and Reddit with this issue.

You can address this via the vimrc support plugin and a custom js function to handle up/down nav.

The solution is described here:

You’ll need to (also described in that plugin’s readme)

  • install vimrc plugin
  • enable js function support (plugin settings page)
  • add the JS functions file to your vault and include the functions I added in the pull req
  • add the corresponding vim mappings to your .obsidian.vimrc
1 Like