VIM如何自动从用户定义的命令返回



我定义了以下命令将文件选择导出到 html文件中,然后使用 Google Chrome将其打开以打印

command! -range WebPrint <line1>,<line2>call Print()
function! Print()
    :'<,'>TOhtml
    :wq
    :!/Applications/Google Chrome.app/Contents/MacOS/Google Chrome %:p.html
endfunction

一个烦人的事情是,每次我执行命令时,VIM部分都消失了,我必须键入Ctrl-c才能返回(击中<Enter>怪异地再次执行命令(。如果有办法在运行命令后自动返回VIM部分?

来自 :help call

    When a range is given and the function doesn't handle it
    itself, the function is executed for each line in the range,

您的Print函数是在没有range的情况下定义的,因此被多次调用,一次在所选范围内的每一行一次。

如果不是您想要的,请删除<line1>,<line2>

另请参见:help function-range-example

最新更新