views:

94

answers:

3

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

I think it should be something like

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

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

+1  A: 

You should be able to use the feedkeys function, whose name is pretty self-explanatory:

function MyPastingFunc()
    call feedkeys("\"+p")  "paste from clipboard
    "do more stuff
endfunction
sleepynate
this solution works just as well as the "correct" answer but I feel normal is better than feedkeys
ScottS
+4  A: 

You are looking for the :normal command:

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

The ! is used to prevent vim also running user mappings that might be part of "+p.

too much php
+2  A: 

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.

Dave Kirby