>> Vimgrep is not very useful to search a single file (use plain "slash"
>> search then). It comes to hand when you have several (maybe many) files
>> to search for a given string or regexp.
>
> Actually (though I don't do it very often) I can see much potential
> use in bringing up the quickfix window with all matches in a single
> file.

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>

I find this useful while programming to bring up a list that shows all
occurrences of a given variable.  This makes it easy to see where the
variable has been used.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to