Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have started learning Vim word-search using * and # while the cursor is over the current word. But this search is limited to the current file buffer.

Is there a command or a shortcut to extend this search to:

  1. all opened tabs?
  2. all opened buffers?
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I don't have an exact solution for your problem, hopefully a better answer than mine will come up. But this is how I tackled the problem of finding a word in all buffers.

" enables to search in all open buffers with :Search <pattern>
command! -nargs=1 Search call setqflist([]) | silent bufdo grepadd! <args> %

nnoremap <left>  :cprev<cr>zvzz
nnoremap <right> :cnext<cr>zvzz

The first line creates a command Search with the search pattern as argument, which writes the results in a quickfix list. The two other lines map the (at least for me) useless arrow keys to something useful; they are mapped to jump to the next/previous Search or to the next/previous compile error, etc., they simply step throu the quickfix list. You can use this as follows:

:Search foobar
share|improve this answer
add comment

It's actually the default behaviour although it may be hard to notice: try * then change to another tab and use n ans N in command mode to jump forward and backward between search hits.

This may make more sense if first you turn highlighting on for all hits:

:set hlsearch
share|improve this answer
+1 only because of hlsearch that I didn't know, and which I would have search for one day or another :-). However, by default I have tried * #, n and N, and it doesn't jump to other file buffers... –  Stephane Rolland Jan 3 '13 at 15:10
No, n and N do not jump buffers (they wrap around), but the term they target is searched for in all tabs; hit * with the highlighting on then cycle thru your tabs -- they will all be highlighted with the same term, so you can use n and N locally there without a fresh search. –  TAFKA 'goldilocks' Jan 3 '13 at 15:28
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.