Wikia

Vim Tips Wiki

Watchlist Recent changes

Search for current word in multiple files

Redirected from VimTip123

Tip 123 Printable Monobook Previous Next

created 2001 · complexity basic · version 6.0


The use of star as in The super star is great. Here is how to use this type of search across a whole directory.

Just add the mappings (or choose different letter combinations):

map gr :grep <cword> *<CR>
map gr :grep <cword> %:p:h/*<CR>
map gR :grep \b<cword>\b *<CR>
map GR :grep \b<cword>\b %:p:h/*<CR>

Mapping one will search for the word under the cursor (like g*) in any of the files in the current directory.

Mapping two will search for the word under the cursor (like g*) in any of the files in the same directory as the current file.

Mapping three will search for the word under the cursor by itself (i.e. surrounded by word boundary like *) in any of the files in the current directory.

Mapping four will search for the word under the cursor by itself (i.e. surrounded by word boundary like *) in any of the files in the same directory as the current file.

CommentsEdit

Only the first of those commands will work when using gvim in Windows Vista.


Need to add a single quote around the \b versions (i.e. grep '\b<cword>\b').

Pages on Vim Tips Wiki

Add a Page
1,586pages on
this wiki
Advertisement | Your ad here

Latest Photos

Add a Photo
71photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki