On Fri, Sep 18, 2009 at 11:29:48PM +0800, Steven Woody wrote:
> I feel happy with ctags except one thing: while I can jump to a
> function/variable definition, I can not however get a list for all the
> references to the function/variable? How vim gurus do it?
I tend to use a big blunt instrument: grep. It works on any
language, not the limited few that cscope/id-utils/global support.
And it works on any string, not just functions/variables.
Here are two scripts/mappings from my .vimrc that I use all the time.
The "_lg" mapping creates a new buffer with the matches, and
the "_le" mapping opens the appropriate file from a given match.
It is limited to grepping from the current directory downward, but I
generally always work from the top level of a project.
" ----- grep on current identifier in top level directory -----
if 1
function! TGrepRun(r)
let curword = expand("<cword>")
if (strlen(curword) == 0)
return
endif
let oreport = &report
let &report = 99999
new
echo "Running grep " . a:r . curword
let s = 'grep ' . a:r . curword . ' * */* */*/* */*/*/* */*/*/*/*'
execute "normal i" . s . "\<Esc>"
execute '1read !' . s . '; :'
2
setlocal nomodified
setlocal bufhidden=delete
let &report = oreport
endfunction
nnoremap _lg :call TGrepRun("-n ")<CR>
nnoremap _lG :call TGrepRun("-ni ")<CR>
endif
" ----- Edit file from 'lid' or 'grep -n' format -----
if 1
" assume curbuf is lid or grep -n output.
" format is ^file:line:text...
function! LidEditFile()
let curline = getline(".")
let matchstart = match(curline, ':\d\+:')
if matchstart >= 0
let matchend = matchend(curline, ':\d\+:')
let pos = strpart(curline, matchstart+1, (matchend-matchstart)-2)
let fname = strpart(curline, 0, matchstart)
execute 'split +' . pos . ' ' . fname
endif
endfunction
nnoremap _le :call LidEditFile()<CR>
endif
--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Gregory H. Margo
gmargo at yahoo/com, gmail/com, pacbell/net; greg at margofamily/org
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---