Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function! s:yank_gist()
let gist_id = input('gist? ')
execute 'Gist' gist_id
let match = matchlist(bufname('%'), '^gist:\(\d*\)/\(.*\)$')
if empty(match)
echoerr 'no match'
return
endif
let gist_url = printf('https://gist.github.com/%s.js?file=%s', match[1], match[2])
let code = join(getline(1, '$'), "\n")
let code = substitute(code, '&', '\&', 'g')
let code = substitute(code, '>', '\>', 'g')
let code = substitute(code, '<', '\&lt;', 'g')
let code = substitute(code, '"', '\&quot;', 'g')
let html = printf('<div><script src="%s"></script><noscript><pre><code>%s</code></pre></noscript></div>',
\ gist_url,
\ code)
let @a = html
endfunction
nnoremap <script> <Leader>G :<C-u>call <SID>yank_gist()<C-m>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment