Here are some tips about using ctags when I code within vim. All resources come from Internet. I'm on a mac OSX Yosemite. First of all, I installed exuberant ctags in homebrew.
brew install ctags
Also, you can download the source code of exuberant ctags, and install it manually.
tar -xzvf ctags-x.tar.gz
cd ctags-x
make
sudo make install
Then go to the root directory of your project. Run:
ctags -R
to create a new tags file for your project. The file contains all information of variable and so on in your code. Last but not least, you need open any program file which you wanna edit within vim, run:
:set tags=root_directory/tags
Now you can edit your code with ctags! Jump to the definition of function or variable where your cursor located by press Ctrl + ] ! Enjoy it!
There two problem I have found while coding.
- Regenerating new tags file should always be the first step of coding when you changed your definition of variables.
- Some program files shoud be excluded every time it runs ctags, the reason might derived from kinds of problem. For me, those files (like /node_modules folder) were too large to be processed.
Regenerating new tags file should always be the first step of coding when you changed your definition of variables.
You should run ctags commend every time code is changed. It's easy but cumbersome.
Some program files shoud be excluded every time it runs ctags
You can specify the excluded files as a parameter of ctags, like:
ctags -R --exclude=dir1 --exclude=dir2 --exclude=dir3
or
ctags -R [email protected]
with the following in .ctagsignore:
dir1
dir2
dir3
And I prefer the latter so that I can manage the excluded files in a consistent place.
Someday I browsed a page from stackoverflow I found a plugin named easytags.vim which could helps you build tags automatically.