Tip #825: Expand #* search to grep-find
tip karma |
Rating 29/8, Viewed by 1300
|
created: |
|
November 19, 2004 17:13 |
|
complexity: |
|
basic |
author: |
|
mosh at albany |
|
as of Vim: |
|
5.7 |
When #/* will not find a word under-cursor,
use the macro 'g/' given below, to expand the
same search with gnu-grep to dirs/files.
Search results are shown in a small window (quickfix mode),
use c-n/c-p to move between results.
Uses gnu-grep on PC/Unix to search vim \<regexp\> in files/trees.
Based on 'grep-find' which is a emacs commands.
" Put this in ~/_vimrc and use g/ to repeat current search as a grep-find.
" Usage
" /xyz .. not found in current file, so lets look for it in *.* with
" g/ .. search for xyz in *.*, next lets look for it in the whole tree
" :call Mosh_grep("../..")
" :call Mosh_grep("/usr/include","strstr")
" GNU-grep -recursive,nocase,linenum,noerror,VimRegexp (in that order).
:set grepprg=grep\ -rinsE
:map g/ :call Mosh_grep()<CR>
function! Mosh_grep(...)
if a:0 == 0
:exec "grep '".@/."' *.*"
elseif a:0 == 1
:exec "grep '".@/."' " a:1
elseif a:0 == 2
:exec "grep" a:2 " " a:1
endif
" Optional mappings for easy navigation of results
:map <c-n> :cnext<CR>
:map <c-p> :cprev<CR>
:copen
endfunction
- Mohsin
http://www.cs.albany.edu/~mosh
<<Choose smaller font in vimdiff mode. |
PHP manual in VIM help format >>
Additional Notes
|