Daniel Nogradi wrote:
Hi vimmers,
I'm sure it has been brought up a couple of times but still I couldn't
find an answer to searching through multiple files in a convenient
way. What I would like vim to do is:
1. search only for keywords like the * command
2. easy way of jumping between matches like n and N for the * command
3. highlight matches like the * command
4. search all files recursively in the directory where the file
currently edited is located
5. only search no need for replacing
So basically I'm looking for a * command that would have an effect
across files. I'm aware of :grep but I couldn't get that to recognize
only keywords, it only does a plain grep.
Would this be possible with vim 6?
I'll take them in the order I'd do them (there is no special sequence
among c1-c5). See ":help quickfix.txt".
a) yank the word under the cursor
yiw
b) search all files recursively. It may take some time. When it's done
you see the first match.
vimgrep /^R"/g ./**/*
where ^R" means "hit the Ctrl-R key and then a double-quote (to insert
the unnamed register). Any other /pattern/ can be used to search for
something else. Characters having a meaning in patterns (such as \ / . $
^ [ ]) must be backslash-escaped. The double asterisk is a special Vim
wildcard meaning "all directories recursively"; it matches only
directories, so for "all _files_ in all directories" we add a single
star after it.
c1) go to next match across all files. The 'switchbuf' option (q.v.)
determines what to do when switching files.
:cn
c2) to previous match
:cN
c3) to first match
:cfirst
c4) to last match
:clast
To make it even faster you can define for instance
:map <F2> :cN<CR>
:map <F3> :cn<CR>
:map <S-F2> :cfirst<CR>
:map <S-F3> :clast<CR>
c5) see all matches (one line per match) in a separate window:
:copen
You can move the cursor there; double-click any match or hit Enter
with the cursor on it, to show it in the other window (where it becomes
the current match).
Best regards,
Tony.