如何从Vim函数中执行Visual模式命令?

7

我有一个函数,它接受一串要执行的命令字符串,并确保在运行这些命令之前打开了'paste'。我需要的类似于以下内容:

vmap <silent> <C-K> :<C-U>call InPasteMode("<Plug>ReplaceVisual")<CR>
function! InPasteMode(command)
  let oldpaste = &l:paste
  try
    set paste
    execute "normal" a:command
  finally
    let &l:paste = oldpaste
  endtry
endfunction

但是命令“<Plug>ReplaceVisual”需要在可视模式下运行,而不是普通模式下运行。
是否有一个类似于:normal的命令可以在可视模式下运行按键呢?
1个回答

13

gv恢复上一次的可视选择。因此,类似execute "normal gv" . a:command这样的命令应该可以工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接