So I was looking at this vim tip for finding in files from within Vim - while it looks helpful, there are a number of possible improvements:
-
Why a static binding? being able to tweak the patterns or the files to search is quite common - so much more value if you could have the command printed in the command line, ready to be edited to your heart’s content or just go ahead and execute the search with Enter.
-
The tip wont work for files without extensions (say .vimrc) - in this case,
expand("%:e")
returns empty string -
lvimgrep
is cross platform but slow - let’s use Mingw grep too forvimgrep
-
And make that Mingw grep integration work on different machines
It was more of an evening of scratching an itch (a painful one if you’re zero in vimscript :) ). Here’s the gist for it- hope someone finds it useful.
Feel free to tweak the mappings - I use the following:
-
leader+f: normal mode: vimgrep for current word, visual mode: search for current selection
-
leader+fd: Similar - but look in the directory of the file and below
-
leader+*: Similar to the above, but use internal grep
Save the file to your .vim folder and source it from .vimrc
so ~/.vim/grephacks.vim
A few notes:
-
GNUWIN is an env variable pointing to some folder where you’ve extracted mingw findutils and grep and dependencies
-
The searches by default work down from whatever vim thinks is your present working directory. I highly recommend vim-rooter if you’re using anything like subversion, mercurial or git as vim-rooter automatically looks for a parent folder that contains .git, .hg or .svn (and more - please look it up)
Happy vimming!