Sometimes I have two windows open and I search for a word that appears in both. Hitting n only cycles through the results in the active window.
It'd be really convenient to somehow jump to the next search result in all open windows.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
You can use
:vimgrep to do your search over the windows and use
'switchbuf' with a value of at least
execute 'vimgrep //j ' . join(map(range(1, winnr('$')), '"#".winbufnr(v:val)'), ' ') set switchbuf+=useopen
Now you can use the quickfix list to jump between matches you searched via
:cprev (I suggest mapping these) or by using the quickfix window,
Personally, I can't really see myself using this kind of search. I typically need to search more files so I use
:grep (I use ripgrep as my
'grepprg'). I use my own
:Cfilter command to grep/filter the quickfix list.
function! s:cfilter(list, bang, pat) let [bool, operator] = a:bang ? ['&&', '!~'] : ['||', '=~'] let pat = a:pat =~ '^/.*/$' ? a:pat[1:-2] : a:pat let pat = pat == '' ? @/ : pat call call('set'.a:list.'list', [(filter(call('get'.a:list.'list', ), "bufname(v:val.bufnr) ".operator." pat ".bool." v:val.text ".operator." pat"))]) echo 'Filtered list: '.(a:bang ? 'not ' : '').'matching '.a:pat.' ('.len(call('get'.a:list.'list', )).' items)' endfunction command! -nargs=1 -bang Cfilter call <SID>cfilter('qf', <bang>0, <q-args>) command! -nargs=1 -bang Lfilter call <SID>cfilter('loc', <bang>0, <q-args>)
:Cfilter foo will filter the list for only entries with
:Cfilter! foo will filter the list with only entries without
For more helps see:
:h :vimgrep :h :_#n :h join() :h map() :h range() :h winnr() :h winbufnr() :h v:val :h :execute :h 'swb'