Search code examples
searchvimfolding

How to show lines matching search in open folds in vim?


How can I show all lines in only open folds that match "foo"?

I tried this per "search only in folded text":

:folddoopen g/foo

but got this error: E147: Cannot do :global recursive


vim version: 7.3 (2010 Aug 15)


Solution

  • :folddoopen and :g cannot be used together in a meaningful way.
    Instead, use :g with foldclosed():

    :g/foo/if foldclosed('.') == -1 | # | endif
    

    For more help see:

    :help :g
    :help /
    :help :if
    :help foldclosed()
    :help :#
    :help :foldopen