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