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 ?
1 Answer
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
-
Thanks . That met the second case of stopping at the encompassing fold .– xquiltJan 3, 2022 at 16:19
-
-
n
/N
map that (1) usessearch()
to get the position of the next match and (2) usesfoldclosed()
/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.