Reputation: 4811
I created a ctag file in my project path:
/home/zen/zen_project
And I can function jump easily into this project.
But however, when I want to jump to builtin module methods(or installed under sys path), such as tornado. I can't do it.
I tried built another tag file in tornado path, but that only enable jumps between tornado files themselves. I still can't jump from my project files to tornado files.
Is it possible to do such jump using vim and ctag, how to do it?
Upvotes: 4
Views: 1582
Reputation: 871
This is an old question, but this is how I do it using virtualenv in Linux.
mkdir test_python
cd test_python
python3 -m venv venv_test
source venv_test/bin/activate
ctags -R .
========================================================
If you open vim, it should now work. Just go to a function and press <C-]>
to go into it. And <C-o>
to go back and <C-i>
to go forward.
Upvotes: 1
Reputation: 172600
You should have one tags
file in your project root, and an additional one in your Tornado root. With the default value of the 'tags'
option, Vim will pick up the files in your current directory, and in the current file's.
You need to explicitly any other locations to it, e.g. by putting this into your ~/.vimrc
:
:set tags+=/path/to/tornado/tags
To check which tag files are considered, you can use:
:echo tagfiles()
Upvotes: 3
Reputation: 24402
I personally use cscope rather than ctags to index my projects as it is a bit more powerful. It is supported in Vim. You generate your index from the files in your project directory then you can use the commands within Vim (or through your shell):
:cscope add /path/to/cscope-database-index # add the database index file
:cscope find f os.py # find file
:cscope find s system # find symbol
:cscope find t TODO # find text string
:cscope find g rmdir # find definition
If you want to add the Python language source code or some module (like tornado), you'd need to index the source directory and add the index using cscope add. Cscope can have database indexes added at once so you should be able to jump into your module's files and Ctrl+o to return to your project.
E.g. For the example of the Python sources:
You can use cscope_maps.vim from http://cscope.sourceforge.net/cscope_vim_tutorial.html to add key shortcuts for the above commands.
I use the following script to generate my database in the current directory (you may only be interested in the .py files):
#!/usr/bin/python
import os
import pdb
import time
import sys
INCLUDED_FILES = ['.py', '.rb', '.java', '.c', '.h', '.cpp', '.cc', '.hpp', '.html', '.js', '.mk', '.xml', '.idl']
EXCLUDED_DIRS = ['.git', '.repo', 'out', '.svn']
OUTPUT_FILE = 'cscope.files'
start_time = time.time()
output_file = open(OUTPUT_FILE, 'w')
current_path = os.path.abspath('.')
for root, dirs, files in os.walk(current_path):
for directory in EXCLUDED_DIRS:
if directory in dirs:
dirs.remove(directory)
for filename in files:
name, extension = os.path.splitext(filename)
if extension in INCLUDED_FILES:
file_path = os.path.join(root, filename)
output_file.write('"%s"' % file_path + "\n")
print(file_path)
# -b: just build
# -q: create inverted index
cmd = 'cscope -b -q'
print(cmd)
os.system(cmd)
elapsed_time = time.time() - start_time
print("\nGeneration of cscope database took: %.3f secs" % elapsed_time)
Hope that helps.
Upvotes: 1