Report abuse

This uses the PastieClient from #528. I've put this in ~/lib/pastie_client.rb which you will see in the Vim code below. Change that require location if you put it somewhere else.


			

		

This is the Vim code, I have ruby compiled in, if you don't - do, it's very neat. If you can't (or won't) then you'll need to write your own macro in Vim to shell-out to the cmdline version, and you'll definitely need xclip or something to read from the copy buffer. This works by Visually highlighting what you want to paste, and hitting p^P, change that binding to whatever you like. If you have xclip installed, then this will use that to put the URL into the select buffer:


			
function! PastiePaste(vmode)
  silent exe "normal! `<". a:vmode. "`>\"ry"
ruby << EOF
  require '~/lib/pastie_client'

  buffer = VIM::evaluate("@r")
  syntax = VIM::evaluate("&filetype")

  p = PastieClient.new
  id = p.paste(buffer,syntax)
  url = "http://pastie.caboo.se/paste/#{id}"
  if system("which xclip >/dev/null 2>&1")
    system("echo '#{url}' | xclip -i")
  end
  puts "Done: #{url}"
EOF
endfunction

:vnoremap p :call PastiePaste(visualmode())

And here's the cmdline version. You can pass it "clipboard" if you want it to use the X clipboard instead of the primary select buffer:


			
#!/usr/bin/env ruby

require '~/lib/pastie_client'

p=PastieClient.new
buffer = ARGV[0] || "primary"
id=p.paste(`xclip -o -selected #{buffer}`)
url = "http://pastie.caboo.se/paste/#{id}"

system("echo '#{url}' | xclip -i -selected #{buffer}")
puts url