Wikia

Vim Tips Wiki

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

Talk0
1,599pages on
this wiki

Recently created tip

We have not yet decided whether to keep this tip as its own page or merge it somewhere else. If you have a suggestion on the tip content, please edit this page or add your comments below (do not use the discussion page).

Please discuss whether to keep this as a new tip, or whether to merge it into an existing tip, on the new tips discussion page.
created February 21, 2012 · complexity basic · version 7.0

I've moved this tip to my blog with more detailed explanation: Generate Ctags Files for C/C++ Source Files and All of Their Included Header Files

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.

CommentsEdit

Advertisement | Your ad here

Photos

Add a Photo
103photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki