2

If I navigate the first line of a folded function with h,l, etc it will open the fold. Navigating search matches with n will also open a fold if there is a match inside the fold.

Can you configure folds to only open when you explicitly open them with z commands?

1
  • No. You can't. Vim handling of folds if utterly broken. Even if you set foldopen= there's bunch of keys that will "nicely" open the fold for you. For example c-o in insert mode when on the folded line.
    – Slava
    Commented Oct 11, 2021 at 8:28

1 Answer 1

5

You can set the 'foldopen' option to control which commands or movements will open folds.

The specific cases you mentioned:

  • h or l: these are horizontal movements, controlled by the hor setting.
  • search or n: these are controlled by the search setting.

So you might want to remove these two specific cases, which you can do with:

set foldopen-=hor foldopen-=search

Or maybe you want to disable all of them and just set 'foldopen' to be empty:

set foldopen=

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.