Sonia Hamilton
Sonia Hamilton

Reputation: 4419

Vim multi-file version of '*' matching command

In vim when you type * on a word (in command mode) it will do a quick search for all matches of that word, in the current file (and highlight the results if hls is set). Is there a quick way of doing this for all open files?

I know about :grep eg :grep foo *.txt. But that involves too much typing (especially on large variable names like doStartCommenceTheWhizzyUpgradeThing.

I know about https://github.com/vim-scripts/Greplace.vim for multi-file find and replaces.

Upvotes: 1

Views: 17

Answers (1)

Sonia Hamilton
Sonia Hamilton

Reputation: 4419

I found a partial solution, I thought I'd let others know. With your cursor on a word, type:

:grep ctrl-r ctrl-w *.txt. The ctrl-r ctrl-w will fill in the current word.

If you have your quickfix list setup, the results will be easy to navigate:

" quickfix list navigation                                                          
" ctrl-n, ctrl-m next, previous; ctrl-k kill (close list)                           
map <C-n> :cnext<CR>                                                                
map <C-m> :cprevious<CR>                                                            
map <C-k> :cclose<CR>

Upvotes: 1

Related Questions