python 的代码跳转

bigzhu posted @ Aug 20, 2010 07:15:11 PM in vim with tags vim python , 11544 阅读

网上基本所有文章说到 python 的代码跳转,使用的都是 ctags.
实在是误人子弟.
不是说不可以,但是 ctags 没有区分 python 的 def xx, class xx,from xx import xx 的,人家毕竟是给 c/c++ 用的.
所以如果一个函数在很多地方都 import 了,那么在 vim 中 g 然后 ctrl+] 的时候,你就可以在10多,20多个选项中免费玩玩'大家来找茬'.
可能还得翻几次页,才能找到哪个才是 def.


其实 python 自己就带了生成 tags 的工具.
执行这个命令来生成 tags:

/home/bigzhu/.local/share/Trash/files/Python-2.5.2/Tools/scripts/ptags.py  *.py

同个文件再跳就是这样的:


不是一般的清爽.

dyh 说:
Nov 16, 2011 06:18:38 PM

你好,我看你写的关于使用ptags在vim进行python代码跳转的文章,
(原文地址:http://bigzhu.is-programmer.com/posts/20676.html)

有个问题想请教:生成了tags文件以后,怎么让它在vim起作用呢?

Avatar_small
bigzhu 说:
Jan 27, 2012 11:41:58 PM

不好意思,我很久没上这里的 blog 了。

要使用很简单。 在 vim 的  配置文件里告诉 vim 用哪个 tag 文件就好了

比如我的 fedora 用的是 ~/.vimrc

加入

 

"自动向父目录找tag 
set tags=tags; 
set autochdir
 
这三行就行了
NCERT English Questi 说:
Sep 29, 2022 08:05:04 PM

Teaching Staff of Leading Educational Institutes have prepared these NCERT 10th Class English Sample Papers 2023 all important questions which has been repeatedly asked in previous years old exams. NCERT English Question Paper Class 10 These NCERT English Question Bank for Reading, Writing, Grammar and Literature questions are prepared from the newly revised syllabus which is listed here.Teaching Staff of Leading Educational Institutes have prepared these NCERT 10th Class English Sample Papers 2023 all important questions which has been repeatedly asked in previous years old exams.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter