HowTo: Use ctags
with source code and deep directory hierarchy
a) Create shell script dirtags.sh
:
#!/bin/bash
cd $1
ctags *
b) Create tags
file for each subdirectory:
find * -type d -exec ~/bin/dirtags.sh {} \;
OR
1) Find and generate tags at once
find . -name *.c -o -name *.cpp -o -name *.h -o -name *.hpp | ctags --append=yes --exclude=bin/* --exclude=.git/* -L -
c) Rebuild tag file for each directory, when working create keymap and save into
~/.vimrc
:
nmap ,t :!(cd %:p:h;ctags *.[ch])&
d) Build global tag file:
cd ~/<project_dir> ctags --file-scope=no -R
e) Configure vim to read local tag file first, if not found, search global tag file:
:set tags=./tags,tags,~/project/tags