如何使用 jedi-vim 转到从另一个文件导入的函数定义?
How can I goto a function definition imported from another file using jedi-vim?
我经常使用 <leader>d
转到函数定义。当此定义来自另一个文件时,它会将我带到文件的导入行。
如何使用 jedi-vim 转到定义在该行导入的函数的文件?
听起来您的配置有问题...仔细检查您的 filetype
确实是 python
。根据 the documentation:
,这应该有效
5.2. g:jedi#goto_command
Function: jedi#goto()
Default: <leader>d
Go to definition (or assignment)
This function first tries jedi#goto_definitions
, and falls back to
jedi#goto_assignments
for builtin modules. It produces an error if
nothing could be found. NOTE: this implementation is subject to
change. Ref: https://github.com/davidhalter/jedi/issues/570
This command tries to find the original definition of the
function/class under the cursor. Just like the
jedi#goto_assignments()
function, it does not work if the definition
isn't in a Python source file.
The difference between jedi#goto_assignments()
and
jedi#goto_definitions()
is that the latter performs recursive
lookups. Take, for example, the following module structure:
# file1.py:
from file2 import foo
# file2.py:
from file3 import bar as foo
# file3.py
def bar():
pass
The jedi#goto_assignments()
function will take you to the
from file2 import foo
statement in file1.py, while the jedi#goto_definitions()
function
will take you all the way to the
def bar():
line in file3.py.
我经常使用 <leader>d
转到函数定义。当此定义来自另一个文件时,它会将我带到文件的导入行。
如何使用 jedi-vim 转到定义在该行导入的函数的文件?
听起来您的配置有问题...仔细检查您的 filetype
确实是 python
。根据 the documentation:
5.2.
g:jedi#goto_command
Function:
jedi#goto()
Default:
<leader>d
Go to definition (or assignment)
This function first tries
jedi#goto_definitions
, and falls back tojedi#goto_assignments
for builtin modules. It produces an error if nothing could be found. NOTE: this implementation is subject to change. Ref: https://github.com/davidhalter/jedi/issues/570This command tries to find the original definition of the function/class under the cursor. Just like the
jedi#goto_assignments()
function, it does not work if the definition isn't in a Python source file.The difference between
jedi#goto_assignments()
andjedi#goto_definitions()
is that the latter performs recursive lookups. Take, for example, the following module structure:# file1.py: from file2 import foo # file2.py: from file3 import bar as foo # file3.py def bar(): pass
The
jedi#goto_assignments()
function will take you to thefrom file2 import foo
statement in file1.py, while the
jedi#goto_definitions()
function will take you all the way to thedef bar():
line in file3.py.