python - 如何在Vim实现go to definition?

查看:199
本文介绍了python - 如何在Vim实现go to definition?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如果在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
它有几大功能:

  • 补全

  • 跳转到定义

  • 显示帮助文档

  • 重命名

使用感觉是性能跟得上去!

这篇关于python - 如何在Vim实现go to definition?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆