Michael Wookey wrote:
> In my .vimrc, I have the following that searches for all
> occurrences of the word under the cursor within the current
> file. The results appear in the quickfix window.
>
> function! SearchCurrentFile()
> let l:filename = expand("%")
> let l:pat = expand("<cword>")
> execute("vimgrep /".l:pat."/gj ".l:filename)
> copen
> endfunction
> nmap <silent> <Leader>f :execute SearchCurrentFile()<CR>
Good stuff (BTW the "execute" in the last line can be just "call").
I checked to see if this needed to be added to the wiki, and found that it is
covered in tip 1543 (with a command rather than a mapping):
http://vim.wikia.com/wiki/Find_in_files_within_Vim
command GREP :execute 'vimgrep /'.expand('<cword>').'/gj '.expand('%') | copen
Can anyone tell me if there is a reason to use "expand('%')" in the above? What
about:
command GREP2 :execute 'vimgrep /'.expand('<cword>').'/gj %' | copen
John
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---