Regex VIM-将正常模式功能转换为命令模式功能

Regex VIM-将正常模式功能转换为命令模式功能,regex,vim,grep,vi,Regex,Vim,Grep,Vi,你好 我有一个映射到CTRL+L的简单函数,我在正常模式下使用该函数搜索一个单词或变量项目中的所有实例: " 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&g

你好

我有一个映射到CTRL+L的简单函数,我在正常模式下使用该函数搜索一个单词或变量项目中的所有实例:

" 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>
通过这种方式,我有效地获得了一个简短而简单的“在所有文件中查找”函数,因此我不必一直键入冗长的
grep
函数。我尝试在
之后修改代码-扩展…
函数的一部分,但我不熟悉编写VI/VIM函数。我熟悉C和BASH脚本,但我无法使该函数按预期工作

我可以从我的映射中得到一些帮助来创建命令模式功能吗

多谢各位


编辑:从@Conner发布修改后的答案。也不包括CTAGS
标签
文件

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>
command!-nargs=1 SearchAll执行“grep-srnw--binary files=不匹配--exclude={*~,tags}--exclude dir=.svn-e.展开(“”)cwindow
地图:SearchAll
命令!-nargs=1 MySearchFunction执行“grep-srnw--binary files=不匹配--exclude=*~--exclude dir=.svn-e.展开(“”)cwindow
映射:MySearchFunction

我可以建议查看ack和ack.vim。

Close,但我有两个问题:1)运行命令后,我得到:E488:尾随字符:cwindow^M 2)这只会找到完全匹配的字符。我该如何查找部分匹配(即:如果搜索我的_全局_VAR,它应该找到我的_全局_VAR_1、我的_全局_VAR_2,等等)。谢谢。通过编辑为我的原始问题添加稍加修改的答案。+1;已接受。@Dogbert:如果在上面两行中的任何一行后面有任何附加字符,可能会导致第一个问题。但我相信您应该按照建议移动到,然后您将有一个更好的工具来执行搜索,并且插件已经实现了这是你想要的命令。
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>
command! -nargs=1 MySearchFunction execute " grep -srnw --binary-files=without-match --exclude=*~ --exclude-dir=.svn  . -e " . expand("<args>") . " " <bar> cwindow
map <C-l> :MySearchFunction <cword><CR>