Wikia

Vim Tips Wiki

Changes: Generate ctags file for a C/C++ source file with all of their dependencies (standard headers, etc)

Edit

Back to page

(Adding categories)
(Insert TipProposed template + minor manual clean)
Line 1: Line 1:
  +
{{TipProposed
  +
|id=0
  +
|previous=0
  +
|next=0
  +
|created=February 21, 2012
  +
|complexity=basic
  +
|author=
  +
|version=7.0
  +
|subpage=/201202
  +
|category1=ctags
  +
|category2=
  +
}}
 
When you want to generate a ctags file for your standard headers, you may have know the following command:
 
When you want to generate a ctags file for your standard headers, you may have know the following command:
+
<pre>
<code>
+
ctags –R --c++-kinds=+p --fields=+iaS --extra=+q /usr/include
ctags –R --c++-kinds=+p --fields=+iaS --extra=+q /usr/include
+
</pre>
</code>
 
 
Yes, this could really work, but sometimes you may got a HUGE tags file, with some extra symbols that has nothing to do with your project. This tip will give you a solution: generate a tags file including symbols of your C/C++ files and their including headers.
 
Yes, this could really work, but sometimes you may got a HUGE tags file, with some extra symbols that has nothing to do with your project. This tip will give you a solution: generate a tags file including symbols of your C/C++ files and their including headers.
   
 
The following shell script would do this for you:
 
The following shell script would do this for you:
+
<pre>
<code>
+
#!/bin/sh
#!/bin/sh
+
gcc -M $* | sed -e 's/[\\ ]/\n/g' | \
gcc -M $* | sed -e 's/[\\ ]/\n/g' | \
+
sed -e '/^$/d' -e '/\.o:[ \t]*$/d' | ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q
sed -e '/^$/d' -e '/\.o:[ \t]*$/d' | ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q
+
</pre>
</code>
 
   
 
Assuming you have saved the code as ctags_with_deps.sh, simple execute
 
Assuming you have saved the code as ctags_with_deps.sh, simple execute
+
<pre>
<code>
+
/path/to/ctags_with_deps.sh file1.cpp file2.c file3.cpp
/path/to/ctags_with_deps.sh file1.cpp file2.c file3.cpp
+
</pre>
</code>
 
   
 
then a tags file containing the symbols of the source files and headers included will be generated.
 
then a tags file containing the symbols of the source files and headers included will be generated.
   
There is also a vim plugin called [http://www.vim.org/scripts/script.php?script_id=3219 ProjectTag] could do this, and could also work on Windows, but it requires you have your vim built with python enabled.
+
The {{script|id=3219|text=ProjectTag}} plugin can also do this, and can work on Windows, but it requires you have your Vim built with Python enabled.
   
==References==
 
<!-- Put any help links you want here in a list as follows: -->
 
[https://gist.github.com/1729992 The shell script]
 
[http://www.vim.org/scripts/script.php?script_id=3219 ProjectTag]
 
 
==Comments==
 
==Comments==
[[Category:ctags ]]
 

Revision as of 09:54, March 27, 2012

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created February 21, 2012 · complexity basic · version 7.0

When you want to generate a ctags file for your standard headers, you may have know the following command:

ctags –R --c++-kinds=+p --fields=+iaS --extra=+q /usr/include

Yes, this could really work, but sometimes you may got a HUGE tags file, with some extra symbols that has nothing to do with your project. This tip will give you a solution: generate a tags file including symbols of your C/C++ files and their including headers.

The following shell script would do this for you:

#!/bin/sh
gcc -M $* | sed -e 's/[\\ ]/\n/g' | \
        sed -e '/^$/d' -e '/\.o:[ \t]*$/d' | ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q

Assuming you have saved the code as ctags_with_deps.sh, simple execute

/path/to/ctags_with_deps.sh file1.cpp file2.c file3.cpp

then a tags file containing the symbols of the source files and headers included will be generated.

The ProjectTag plugin can also do this, and can work on Windows, but it requires you have your Vim built with Python enabled.

Comments

Around Wikia's network

Random Wiki