Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created March 30, 2012 05:47
Show Gist options
  • Save itspriddle/2246959 to your computer and use it in GitHub Desktop.
Save itspriddle/2246959 to your computer and use it in GitHub Desktop.
" A ghetto gister for Vim.
" Requires gist <https://github.com/defunkt/gist>
"
" Usage:
" :'<,'>Gist
command -range=% Gist call s:Gist(<line1>, <line2>, <f-args>)
function! s:Gist(line1, line2, ...)
let d1 = join(getline(a:line1, a:line2), "\n")
let d2 = substitute(d1, '"', '\\"', 'g')
let d3 = substitute(d2, '`', "\\\\`", 'g')
let d4 = substitute(d3, "\\$", "\\\\$", 'g')
let ext = expand('%:e')
if ext =~ 'markdown'
let ext = 'md'
endif
let cmd = 'echo "'.d4.'" | gist -p -t '.ext.' -'
let r = system(cmd)
echo substitute(r, "$", "", 'g')
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment