Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Ctags to list all the references of a symbol(tag) in vim?

Tags:

vim

ctags

Can I list all the references of a symbol in vim using Ctags? like the 'Find References' In some GUI IDE.

The Ctag tutorial just tell how to locate the definition of a symbol ,not all the usages.

like image 278
Shaobo Zi Avatar asked Jun 10 '15 10:06

Shaobo Zi


People also ask

How do I list tags in Vim?

You can position the cursor over the tag and press g Ctrl-]. You can visually select a text and press g Ctrl-] to jump or list the matching tags. You can use the 'stjump' ex command. This will open the matching or selected tag from the tag list in a new window.

What is ctags and Cscope?

cscope, ctags, and Vim are powerful tools for reading a lot of code. ctags can be used to take you to the definition of a variable (e.g., a function, variable, or macro). cscope can be used to take you to the call site of a definition (e.g., all function calls, all variable uses, all macro uses).


1 Answers

The ctags tool only collects and stores the definitions of symbols.

To find all references, you can use the cscope integration into Vim (:help cscope), but note that cscope supports far fewer programming languages than ctags.

Alternatively, a poor man's substitute would be the built-in :grep / :vimgrep commands (with proper patterns). Remember, Vim is a powerful text editor, but no IDE. Either you find and integrate a suitable external tool for this, or switch to a real IDE (like Eclipse, Visual Studio, or IntelliJ IDEA) for such code browsing.

like image 187
Ingo Karkat Avatar answered Oct 07 '22 09:10

Ingo Karkat