Hi i'm finding the simplest way to search in vim, i don't have anything on my workflow yet, only the / command. Currently i'm using this line
map <F3> :execute "vimgrep /" . expand("<cword>") . "/j **" <Bar> cw<CR>
On my .vimrc so i put the cursor on the word, hit F3 and it searches f开发者_如何学JAVAor that word on the current dir and subdirs, i wish i could change the <cword> for the contents of the current visual block and use grep instead, because vimgrep is too slow the problem is grep doesnt output to the quick fix window. Any ideas on doing searches with the content of the current visual block? Or redirecting the ouput of grep to the quick fix list?
Vim has a :grep command that behaves like :vimgrep. I think this should give you what you want:
map <F3> :execute "grep " . expand("<cword>") . " **" <Bar> cw<CR>
BTW, seeing your use case (searching for the word under the cursor), you may want to try using tag files ( http://vim.wikia.com/wiki/Browsing_programs_with_tags ).
You can find a friendlier version of the mapping above in this gist. Just save it to a file (say ~/vimscripts/fastgrep.vim)
Add to your .vimrc:
source ~/vimscripts/fastgrep.vim
now you can:
highglight the word in vim and hit \g (i.e. <leader> g)
You'll be prompted (in vim prompt area):
Search for text: <highlighted_word_but_you_can_change_it>
Files to search: *.rb
Hit enter, and you'll see results in the QuickResults window so you can just click to jump to those lines or use :cp :cn to navigate through the matches.
If you'd like to change *.rb to whatever you most frequently search in, just edit the vimscript and source it again.
精彩评论