[英]VIM + Python - “gd” command not working properly
我开始使用VIM对Python进行编程。 我遇到了一些问题,希望有人可以帮助我解决这个问题。
应该使用“ gd”命令将您带到当前函数中定义/使用的变量的第一个位置。 据我了解,这与执行“ [[”到函数顶部,然后搜索变量名相同。
问题是,当我在Python函数中尝试此操作时,vim会在整个文件中找到该变量的第一个匹配项。
为什么会发生这种情况/如何解决?
我认为问题是由于Vim处理功能的方式引起的。 从[[
的文档中:
*[[*
[[ [count] sections backward or to the previous '{' in
the first column. |exclusive|
Note that |exclusive-linewise| often applies.
除非以某种方式专门为某个地方的python文件定义了一个部分(我不认为这是可能的,因为它们应该是两个字母的nroff部分),否则将假定第一列中应该有一个大括号,与python文件无关。
我建议在Vim邮件列表中询问是否有任何插件或解决方法。 或者,您可以定义如下映射:
nmap gd :let varname = '\<<C-R><C-W>\>'<CR>?\<def\><CR>/<C-R>=varname<CR><CR>
可以通过功能更优雅地完成此操作,但这只是一个应该起作用的快速技巧。 它将gd
映射到一个函数,该函数将变量'varname'设置为保留光标所在的单词,向后搜索def,然后向前搜索该变量:
:let varname = " Variable setting
'\< " String start and word boundary
<C-R><C-W> " Ctrl-R, Ctrl-W: pull in the word under the cursor
\>' " Word boundary and string end
<CR> " Enter - finish this command
? " Search backwards for...
\<def\> " def but not undefined etc (using word boundaries)
<CR> " Enter - Perform search
/ " Now search forward
<C-R>= " Pull in something from an expression
varname<CR> " The expression is 'varname', so pull in the contents of varname
<CR> " Enter - perform search
我没有在Vim配置中重新定义varname,它工作良好,但是我已经用python编译了vim。 也许这是问题所在?
您是否已安装VIM版本7.x,并使用Python支持对其进行了编译? 要检查这一点,请在VIM中输入:python print “hello, world”
。 如果您看到类似E319: Sorry, the command is not available in this version
的错误消息E319: Sorry, the command is not available in this version
,那么该是获取新E319: Sorry, the command is not available in this version
的时候了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.