繁体   English   中英

VIM-将普通模式功能转换为命令模式功能

[英]VIM - Convert normal-mode function to command-mode function

美好的一天,

我有一个简单的函数,已映射到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>

我正在尝试使命令模式的功能,所以我可以做这样的事情:

:mySearchFunction wordToFind

这样,我有效地得到了一个简短的“查找所有文件”功能,因此我不必一直都在键入冗长的grep函数。 我曾尝试在修改代码. -e " .expand... . -e " .expand...函数的一部分,但我不熟悉编写VI / VIM函数。我熟悉C和BASH脚本,但无法使此函数正常工作。

我可以从我的这种映射中获得一些命令模式功能的帮助吗?

谢谢。


编辑:从@Conner发布答案的修改版本。 也排除CTAGS tags文件。

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>

可能我建议调查ack和Ack.vim。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM