3

我想编写一个 vim 函数,其中包括从剪贴板粘贴(如果重要的话,windows)

我认为应该是这样的

function MyPastingFunc()
  "+p  "paste from clipboard
  "do more stuff
endfunction

当然 "+p 只是 .vim 文件中的注释。我怎样才能使它工作?

4

3 回答 3

5

您正在寻找:normal命令:

function MyPastingFunc()
  "paste from clipboard
  normal! "+p
  "do more stuff
endfunction

!用于防止 vim 也运行可能"+p属于.

于 2010-07-01T03:08:00.203 回答
2

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.

于 2010-07-01T18:33:00.603 回答
1

您应该能够使用 feedkeys 功能,其名称非常不言自明:

function MyPastingFunc()
    call feedkeys("\"+p")  "paste from clipboard
    "do more stuff
endfunction
于 2010-07-01T02:38:26.217 回答