Last active
December 27, 2015 20:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 = "[email protected]:/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