Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim go to next search result across multiple files?

Tags:

vim

vi

When I use source insight before, when I search for some word I can press the "search forward" button to jump to next match across all project files.

For example:

  1. Search "apple"
  2. Source Insight list all project contain "apple" word (ex: 15 result )
  3. Press "search forward button"
  4. Cursor jumps to next search result, repeat as needed to see all 15 results

But using vim with cscope, I need something like:

  1. :cs find s "apple"
  2. cscope list 15 result
  3. input "1" and jump to first result
  4. :cs find s "apple"
  5. cscope list 15 result
  6. input "2" and jump to second result

It's very complex.

Is there a better way to do this in Vim?

like image 386
CK vir Avatar asked Oct 22 '25 20:10

CK vir


1 Answers

Vim allows you to redirect cscope's output to the quickfix window with the 'cscopequickfix' option. Below is the suggested value in :help 'cscopequickfix':

set cscopequickfix=s-,c-,d-,i-,t-,e-

From there, you can search for apple with:

:cs f s apple

view the list of matches with:

:cw[indow]

jump to the next match with:

:cn[ext]

jump to the previous match with:

:cp[revious]

and, of course, use the mouse or the keyboard to select entries in the quickfix window.

Bonus: add this to your vimrc to skip the :cwindow step:

augroup qf
    autocmd!
    autocmd QuickFixCmdPost * cwindow
augroup END
like image 159
romainl Avatar answered Oct 25 '25 21:10

romainl