Vim-Pydoc插件不使用运算符映射

Vim-Pydoc插件不使用运算符映射,vim,Vim,我有一个小的操作符映射用于。其代码如下: nnoremap <buffer> <localleader>d :set operatorfunc=<SID>PydocOperator<cr>g@ vnoremap <buffer> <localleader>d :<c-u>call <SID>PydocOperator(visualmode())<cr> function! s:Pydoc

我有一个小的操作符映射用于。其代码如下:

nnoremap <buffer> <localleader>d :set operatorfunc=<SID>PydocOperator<cr>g@
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
这很奇怪,因为:Pydoc应该作为一个普通命令工作,只接受一个参数作为输入。我查看了定义了:Pydoc命令的代码,这行代码被删除,并发现将参数传递给:Pydoc命令可能会导致问题。因此,我运行了:Pydoc'sys'以查看它是否会抛出与运算符映射相同的错误,它确实这样做了。因此,如果参数周围的引号有问题,如何格式化execute命令,使其不会给出无效参数?

shellescape函数对于:Pydoc命令不是必需的。shellescape在返回的字符串中包含引号,这会导致:Pydoc自毁。但是,例如,如果命令为:grep,则需要使用shellescape

相关帮助主题:

:help shellescape()
:help 'operatorfunc'
:help :map-operator
此外,还应结合使用:map,以便它仅在Python缓冲区中定义,如:Pydoc命令。
execute 'Pydoc ' . shellescape(@@)
:help shellescape()
:help 'operatorfunc'
:help :map-operator