我想编写一个 vim 函数,其中包括从剪贴板粘贴(如果重要的话,windows)
我认为应该是这样的
function MyPastingFunc()
"+p "paste from clipboard
"do more stuff
endfunction
当然 "+p 只是 .vim 文件中的注释。我怎样才能使它工作?
您正在寻找:normal
命令:
function MyPastingFunc()
"paste from clipboard
normal! "+p
"do more stuff
endfunction
!
用于防止 vim 也运行可能"+p
属于.
If you always want to past into a new line you can use the :put
command, e.g:
:put + will paste after the current line
:put! + will paste before the current line
:123 put + will paste after line 123
N.B. it will also move the cursor position to the first non-blank character of the inserted text. This may or may not be what you want.
您应该能够使用 feedkeys 功能,其名称非常不言自明:
function MyPastingFunc()
call feedkeys("\"+p") "paste from clipboard
"do more stuff
endfunction