简体   繁体   中英

How to go all reference of a text in whole project using vim

I know this is very simple question and really there are very huge source of information but I really not able to find the solution to my question.

I have tried with cscope and got the references but then once I am in the file not find the way to go go to the next occurrence.

I know the use of Ctrl+] with ctags but that is not what I want.I want to go all the reference of a text one by one .

like when we want to change a prototype of a function and want to go one by one.

Hope there is some way for it.

You are looking for :tnext and :tprevious .

Read the following help topics:

:help tags
:help ctags
:help cscope

But here is a generic "search/replace in project" method…

  1. search for that string in your whole project and list the matching lines in the quickfix window:

     :vim foo **/*.py | cw 
  2. record your change in a simple macro:

     qq ciwbar<Esc> :cnext<CR> q 
  3. repeat that change for every match in the list:

     @q @@ @@ … 

    skipping irrelevant matches with :cnext .

and another one…

  1. open a new tab:

     :tabnew<CR> 
  2. populate the local argument list with files that contain your search pattern:

     :arglocal `grep -Rl foo *.js`<CR> 
  3. perform a global search/replace on every file in the local argument list

     :argdo %s/foo/bar/gc<CR> yyyynnnyyy… 

Are you using the cscope plugin for vim ?

After searching for something you can use :cnext and :cprev to go through the results. If that's too cumbersome, you can add a shortcut to your .vimrc ; for example:

noremap nn :cnext <CR> , which will make nn a shortcut for :cnext .

If it is for search pattern in whole project. You can try

ack.vim there is 36 contributor so it's a well done plugin using ack . I tried it in a big project few weeks ago and it improve well my workflow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM