我在项目路径中创建了一个ctag文件:
/home/zen/zen_project我可以很容易地跳到这个项目中。
但是,当我想跳转到内置模块方法(或安装在sys路径下)时,比如龙卷风。我不会做。
我尝试在龙卷风路径中构建另一个标记文件,但这只允许在龙卷风文件之间跳转。我仍然不能从我的项目文件跳转到龙卷风文件。
是否可以用vim和ctag进行这样的跳转,怎么做呢?
发布于 2014-07-29 10:42:12
您的项目根目录中应该有一个tags文件,而龙卷风根目录中应该有一个额外的文件。使用'tags'选项的默认值,Vim将获取当前目录和当前文件中的文件。
您需要显式地使用它的任何其他位置,例如将其放入~/.vimrc中。
:set tags+=/path/to/tornado/tags要检查考虑了哪些标记文件,可以使用:
:echo tagfiles()发布于 2014-07-29 01:33:24
我个人使用cscope而不是ctag来索引我的项目,因为它更强大一些。它在Vim中得到支持。您可以从项目目录中的文件生成索引,然后可以使用Vim中的命令(或通过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如果您想要添加Python语言源代码或某些模块(如龙卷风),则需要对源目录进行索引,并使用cscope添加索引。Cscope可以立即添加数据库索引,因此您应该能够跳入模块的文件和Ctrl+o以返回到您的项目。
例如,对于Python源代码的示例:
您可以使用来自cscope_maps.vim的tutorial.html添加上述命令的键快捷方式。
我使用以下脚本在当前目录中生成我的数据库(您可能只对.py文件感兴趣):
#!/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) 希望这能有所帮助。
发布于 2022-07-18 20:01:04
这是一个老生常谈的问题,但这是我如何在Linux中使用virtualenv实现的。
mkdir test_python
cd test_python
python3 -m venv venv_test
source venv_test/bin/activate
ctags -R .
========================================================
如果您打开vim,它现在应该可以工作了。只需转到一个函数,然后按<C-]>键进入它。<C-o>回去,<C-i>向前走。
https://stackoverflow.com/questions/25006821
复制相似问题