1

While navigating between search pattern matches , if one of the matches happened to be embedded within a block of text , the whole block gets unfolded .
Is there a way to substitute this behavior with one that highlights the one-liner folded text or effortlessly just stop at it during navigation ?

2
  • You could probably write a custom n/N map that (1) uses search() to get the position of the next match and (2) uses foldclosed()/foldclosedend() to check on the folds. Then you could do whatever it is you want regarding jumping to a match or the fold or whatever, making sure to respect 'wrapscan'. But note that if you jump to the beginning of a fold containing a match, the next match will always be the one in the fold… so if you want to later "skip" over it, you need to handle that case.
    – D. Ben Knoble
    Jan 3, 2022 at 13:52
  • @D.BenKnoble I currently only know the bare common knowledge about vim . With such implementation involving logical conditionals and exceptions , i don't think i'm up to implement it . Nonetheless i did grasp the abstract concept itself .
    – xquilt
    Jan 3, 2022 at 16:02

1 Answer 1

2

See :help 'foldopen':

                        *'foldopen'* *'fdo'*
'foldopen' 'fdo'    string (default: "block,hor,mark,percent,quickfix,
                                 search,tag,undo")
            global
            {not available when compiled without the +folding
            feature}
    Specifies for which type of commands folds will be opened, if the
    command moves the cursor into a closed fold.  It is a comma separated
    list of items.
    NOTE: When the command is part of a mapping this option is not used.
    Add the zv command to the mapping to get the same effect.
    (rationale: the mapping may want to control opening folds itself)

So you can remove the 'search' from the default in your .vimrc:

set foldopen-=search
3
  • Thanks . That met the second case of stopping at the encompassing fold .
    – xquilt
    Jan 3, 2022 at 16:19
  • @D.BenKnoble indeed , it made the exclusion more distinguishable .
    – xquilt
    Jan 3, 2022 at 16:38
  • @D.BenKnoble agreed and updated
    – mattb
    Jan 3, 2022 at 17:19

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.