如果在views.py
文件中有一处用到了User
类,当cursor在User()
下面的时候请问有什么方式能快速跳转到models.py
下面的User
类的实现处?
# views.py
from models import User
u = User()
使用CtrlP
打开一个文件然后跳到相应的实现处的方式还是太慢了,在阅读大一点项目的源代码的时候这样思维很容易被打断。
查到了一款插件tagbar,通过:TagbarToggle<CR>
可以起到下面这样的效果,但是这样的话还是只能浏览到本文件下面的所有class以及function。
答案
jedi-vim
Completion <C-Space>
Goto assignments <leader>g (typical goto function)
Goto definitions <leader>d (follow identifier as far as possible, includes imports and statements)
Show Documentation/Pydoc K (shows a popup with assignments)
Renaming <leader>r
Usages <leader>n (shows all the usages of a name)
Open module, e.g. :Pyimport os (opens the os module)
ycm
The GoToDeclaration subcommand
Looks up the symbol under the cursor and jumps to its declaration.
Supported in filetypes: c, cpp, objc, objcpp, cs, go, python, rust
The GoToDefinition subcommand
Looks up the symbol under the cursor and jumps to its definition.
NOTE: For C-family languages this only works in certain situations, namely when the definition of the symbol is in the current translation unit. A translation unit consists of the file you are editing and all the files you are including with #include directives (directly or indirectly) in that file.
Supported in filetypes: c, cpp, objc, objcpp, cs, go, javascript, python, rust, typescript
The GoTo subcommand
This command tries to perform the "most sensible" GoTo operation it can. Currently, this means that it tries to look up the symbol under the cursor and jumps to its definition if possible; if the definition is not accessible from the current translation unit, jumps to the symbol's declaration. For C/C++/Objective-C, it first tries to look up the current line for a header and jump to it. For C#, implementations are also considered and preferred.
Supported in filetypes: c, cpp, objc, objcpp, cs, go, javascript, python, rust
个人推荐 jedi-vim
它有几大功能:
补全
跳转到定义
显示帮助文档
重命名
使用感觉是性能跟得上去!