ctags doesn't support that - it only generates a list of symbols and a
little bit of metadata about each, it doesn't generate a
cross-reference of what symbols are called by what other symbols. You
can try using cscope instead (or in addition), though - it does make
that cross referencein addition to the flat list of symbols.
~Matt
On Fri, Sep 18, 2009 at 8:29 AM, Steven Woody <narke...@gmail.com> wrote:
> Hi,
> 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?
>
You need to use cscope or GNU global or Gnu id-utils for this.
You can get more information about these tools from the following
links:
http://cscope.sourceforge.net/
http://www.gnu.org/software/global/
http://www.gnu.org/software/idutils/manual/idutils.html
Cscope can be used from within Vim. Refer to the following help topic
for more information on this:
:help cscope
To use GNU id-utils from Vim, refer to the following Vim plugin:
http://www.vim.org/scripts/script.php?script_id=251
To use GNU global from Vim, refer to the following page:
http://www.gnu.org/software/global/globaldoc.html#SEC26
- Yegappan
:help cscope
Regards,
Gary
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
Are you aware of vim's built-in :grep command?
:help :grep
For jumping to particular lines in files from a <file name>:<line
number> pair in a buffer there are:
:help CTRL-W_F
:help gF
> It is limited to grepping from the current directory downward, but I
> generally always work from the top level of a project.
To have grep search recursively through a directory hierarchy, just
use the -r or -R option. Then you can easily specify the top-level
directory and whether or not you want to search recursively. The
--include and --exclude options can also help narrow your search if
your directories contain a mix of file types.
HTH,
Gary
+1 for this suggestion. It has several advantages, not the least of
which being that it is much simpler. And it uses the quickfix list.
:help quickfix
While we're talking about searching source code, I would like to
direct your attention to ack: http://betterthangrep.com/
Set your 'grepprg' to ack. It will change your life.
--
Erik Falor
Registered Linux User #445632 http://counter.li.org
Yes, but it is unsuitable. The goal of my script is to create a buffer
with a location list in it. How does :grep do that?
Jump to the first match is _never_ what I want. And it's noisy. And
needs an extra step to get the list, a ":copen". And there's only one
quickfix list. Could use :lgrep and :lopen to get multiple location
lists. (And where does :lopen get off ignoring my setting for
'splitbelow'?) Is there a way to get the location list associated
with a :grep without jumping to the first file?
> For jumping to particular lines in files from a <file name>:<line
> number> pair in a buffer there are:
> :help CTRL-W_F
> :help gF
Which does not work work if 'isfname' contains a colon.
I'm mostly working with perl, and ftplugin/perl.vim adds a colon to
'isfname', so this breaks gF. Yes I could undo it, but there are
reasons to keep it.
And gF does not seem to work right on a location list generated with
:lopen. I'm not sure what it's doing. Some kind of quickfix mode -
also something I never want.
> > It is limited to grepping from the current directory downward, but I
> > generally always work from the top level of a project.
> To have grep search recursively through a directory hierarchy, just
> use the -r or -R option. Then you can easily specify the top-level
> directory and whether or not you want to search recursively. The
> --include and --exclude options can also help narrow your search if
> your directories contain a mix of file types.
The shell does what I want: sorting, ignoring dot directories like .svn
or .git, and ordering by hierarchy depth. "grep -R" does not even sort.
gm
Hi,
I am just learning how to use ctags. From the looks of this thread, I
gather cscope can do more than ctags. Is worth to skip learning ctags
and just jump into cscope? Thanks.
Please bottom post on this mailing list.
Cscope can do everything that ctags can do and much more, but for a
smaller set of languages. So, it's probably worth knowing both.
~Matt
Is it so difficult to understand that:
a. I wrote a script that does what I want.
b. :grep does NOT do what I want.
End of story.
I use the vim project plugin. It has a nice function binded to
<leader>G that search recursively in a project.
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3