5

I want to write a function myFunc such that:

myFunc /function foo/

becomes

:vimgrep /function foo/ **/*.cpp **/*.hpp

and

myFunc /class bar: public/

becomes

vimgrep /class bar: public/ **/*.cpp **/*.hpp

how do I do this?

Thanks!

anon
  • 41,035
  • 53
  • 197
  • 293
  • Wow, thanks for pointing my nose to vimgrep. That sounds very useful. Loving vim, you learn something new even after 10+ years of usage. – jhwist Feb 03 '10 at 09:51

2 Answers2

5
:command -nargs=1 MyFunc vimgrep <args> **/*.cpp **/*.hpp

:MyFunc /Hello world/
Mykola Golubyev
  • 57,943
  • 15
  • 89
  • 102
0

You might want to checkout a plugin I wrote called EasyGrep. It has builtin support for this when you use tracked mode. What you can do is place your cursor over a word (or visually select some text) and type <leader>vv and it will search all of *.cpp *.hpp *.cxx *.hxx *.cc *.c *.h for the pattern. Once you get used to typing <leader>vv it is significantly faster than typing :Command /Pattern/.

danprice
  • 1,184
  • 1
  • 7
  • 3