Good day,
I have a simple function I have mapped to CTRL+L which I use in normal-mode to search for all instances in a project of a word or variable:
" Find all occurences in files
map <C-l> :execute " grep -srnw --binary-files=without-match --exclude=*~ --exclude-dir=.svn . -e " . expand("<cword>") . " " <bar> cwindow<CR>
I am trying to make a command-mode function out of this so I could do something like:
:mySearchFunction wordToFind
This way, I effectively get a short and simple “Find in All Files” function so I don’t have to type the lengthy grep function above all the time. I have tried modifying the code after the . -e " .expand... piece of the function, but I am not familiar with writing VI/VIM functions. I am familiar with C and BASH scripting, but I cannot get this function working as expected.
May I have some assistance with making a command-mode function from this mapping of mine?
Thank you.
Edit: Posting modified version of the answer from @Conner. Also excludes the CTAGS tags file.
command! -nargs=1 SearchAll execute " grep -srnw --binary-files=without-match --exclude={*~,tags} --exclude-dir=.svn . -e " . expand("<args>") . " " <bar> cwindow
map <C-l> :SearchAll <cword><CR>
Might I suggest looking into ack and Ack.vim.