Paste from clipboard in vim script

I want to write a vim function that includes pasting from the clipboard (if that matters on Windows)

I think it should be something like

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

Of course, "+ p is just a comment in the .vim file. How can I do this work?

+3
source share
3 answers

You are looking for a command :normal:

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

!used to prevent vim from matching user accounts that may be part of "+p.

+4
source

If you always want to jump to a new line, you can use a command :put, for example:

:put +      will paste after the current line
:put! +     will paste before the current line
:123 put +  will paste after line 123

N.B. . , .

+2

feedkeys, :

function MyPastingFunc()
    call feedkeys("\"+p")  "paste from clipboard
    "do more stuff
endfunction
+1

Source: https://habr.com/ru/post/1752563/


All Articles