naive231
naive231

Reputation: 1380

How can I find content except folded contents in vim?

Folding feature with syntax method is pretty well, and it can used to make a kind of "function list". But if I want to find a function name with '/', vim will locate the cursor on the folded line to indicate that candidate is in folded contents. Can I avoid this behavior?

Upvotes: 0

Views: 36

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172600

If you want the fold to open to show the obscured match, you have to restore the default behavior via

:set foldopen+=search

If you want to jump over (effectively ignoring) matches inside folds, that can be done with a mapping variant of the next search match command which checks for a closed fold and then re-invokes itself:

:nnoremap ,n n:if foldclosed('.') != -1<Bar>execute 'normal ,n'<Bar>endif<CR>
:nnoremap ,N N:if foldclosed('.') != -1<Bar>execute 'normal ,N'<Bar>endif<CR>

Upvotes: 1

Related Questions