我希望编写一个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
。
如果您希望始终将内容粘贴到新行中,可以使用:put
命令,例如:
:put + will paste after the current line
:put! + will paste before the current line
:123 put + will paste after line 123
你应该能够使用feedkeys函数,其名称相当自说明:
function MyPastingFunc()
call feedkeys("\"+p") "paste from clipboard
"do more stuff
endfunction