Skip to content

Instantly share code, notes, and snippets.

@acrisci
Last active December 27, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acrisci/7382100 to your computer and use it in GitHub Desktop.
Save acrisci/7382100 to your computer and use it in GitHub Desktop.
Share your vim buffer with others easily with your own personal pastebin-like system.
" Personal Pastebin
" Based on <http://connermcd.com/blog/2012/09/17/personal-pastebin-system/>
com! -range=% HtmlPaste <line1>,<line2>call HtmlPaste()
noremap <silent> gH :HtmlPaste<cr>
fun! HtmlPaste() range
" *********
" Settings
let localPaste = "~/projects/octopress/source/paste"
let remotePublic = "tony@example.com:/srv/www/example.com"
let remotePasteUrl = "http://example.com/paste"
" *********
let hasRN = &relativenumber
let hasNumber = &number
" unset line numbers - makes copy/paste easier for people
set norelativenumber
set nonumber
" convert to html
exe a:firstline.",".a:lastline."TOhtml"
" get a random alphanumeric string for the filename
let pasteName = system("cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1 | perl -ne 'chomp and print'")
" save to local paste directory
exe "sav! " . localPaste . "/" . pasteName
" close window the above command creates
wincmd c
" sync local/public paste
exe "silent !rsync -a " . localPaste . " " . remotePublic
" copy to clipboard
exe "silent !echo -n '" . remotePasteUrl . "/" . pasteName . "' | xclip -selection clipboard"
" restore line numbers
if hasRN
set relativenumber
endif
if hasNumber
set number
endif
redraw!
endfun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment