jkang
jkang

Reputation: 549

How do I search for and then jump to a word in another file in vim

In particular, I'm editing files in Verilog and would like to see other instances of a word under the cursor in other files. Ideally, it'd bring up a list like the auto-complete list. I can then select the line entry and vim would open the file (either in the same window or a new tab).

I've seen this feature in Emacs. I have to think it exists in Vim somewhere.

Upvotes: 0

Views: 544

Answers (3)

Vitor
Vitor

Reputation: 1976

If you have a tags file available, you might be able to use :tselect identifier for that purpose.

Upvotes: 1

sashang
sashang

Reputation: 12234

Vimgrep is your friend.

:vimgrep /pattern/ <path>/**

This will add lines to the quickfix window. Each line is the text from the line in a file that matches the pattern. The ** is shorthand for recurse into subdirectories.

Upvotes: 0

BananaNeil
BananaNeil

Reputation: 10772

This would be really fun to write in vimscript, but I don't exactly have time at the moment. Hopefully this will get you going in the right direction:

There is a vim plugin called Fugitive

It allows you to do things like git grep, or git blame right from you vim console. https://github.com/tpope/vim-fugitive

Their git grep command, Ggrep, should get you a list of local files with whatever word you want to grep for. Possibly check out this Q/A for getting it to work nicely: Getting 'git grep' to work effectively in vim

Last thing I would do is write a little vimscript function and a keystroke alias that would call Ggrep with the word under the cursor.

(hopefully I'll have time to write a better answer later)

Upvotes: 1

Related Questions