>> Well, something 100% untested would be something like
>>
>> :nnoremap <f8> :grep -r '<c-r><c-w>' *<cr>
>
> The issue with this solution is that it "only does a plain
> grep" as I noted in my original mail. It will match the word
> against *any* appearance of it, for example if your cursor is
> on the word "approx" which is a function name in your C code
> then it will also match the word "approximation" in any of the
>  comments. While the * command only matches words which are
> exactly "approx" and will not match "approximation". This is
> the behaviour I'm looking for accross multiple files.

Ah...try changing it to (again, 100% untested)

        :grep -r '<bslash><lt><c-r><c-w><bslash>>' *<cr>

(you might not have to escape those backslashes)  Assuming the
underlying grep mechanism supports it, it makes use of \<...\> to
ensure word-boundaries.  GNU grep seems to work with \<...\> but
I don't know about any sort of internal greppage, or non-GNU grep
versions.

        :help \<

Just another idea to try...

Great! Thanks a lot, this works just the way I like it, only matching
exact words not subwords. So after all my mapping became (just in case
someone was interested):

map <buffer> gr :w<cr>:grep -r --exclude=tags
'<bslash><lt><c-r><c-w><bslash>>' %:p:h/<cr><cr><cr>:cn<cr>

And this mapped 'gr' to (1) save the file (otherwise vim would have
been complaining about unsaved files before jumping to the next) (2)
look for the word under the cursor in every file in the directory of
the file but exclude 'tags' which will obviously match (3) jump to the
first match.

Thanks again!

Reply via email to