Created
July 17, 2012 14:21
-
-
Save bouzuya/3129678 to your computer and use it in GitHub Desktop.
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
| 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, '<', '\<', 'g') | |
| let code = substitute(code, '"', '\"', '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