0
我有一个小型运算符映射,用于Pydoc plugin。它的代码如下:Vim - Pydoc插件不能与运算符映射一起使用
nnoremap <buffer> <localleader>d :set operatorfunc=<SID>PydocOperator<cr>[email protected]
vnoremap <buffer> <localleader>d :<c-u>call <SID>PydocOperator(visualmode())<cr>
function! s:PydocOperator(type)
let l:orig_register = @@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
execute 'Pydoc ' . shellescape(@@)
let @@ = l:orig_register
endfunction
然而,VIM将引发一个错误:
execute 'Pydoc ' . shellescape(@@)
:如果我手动复制一些文字并运行此命令
E116: Invalid arguments for function <SNR>117_ShowPyDoc
同样的错误发生这很奇怪,考虑到:Pydoc
应该作为一个正常的命令,以一个参数作为输入。我查看了定义:Pydoc
命令的代码(该行代码为here),并发现将参数传递给引号中的:Pydoc
命令可能会导致问题。所以我跑:Pydoc 'sys'
看看它是否会抛出与运算符映射相同的错误,它会这样做。因此,如果它在参数周围存在引号问题,我如何格式化execute
命令,以便它不提供无效参数?
此外,你应该使用':地图'与'联合',所以它在Python缓冲区只被定义(如':Pydoc'命令)。 –
2015-02-07 20:48:56