Skip to content

Instantly share code, notes, and snippets.

@zerowidth
Created July 21, 2011 01:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zerowidth/1096346 to your computer and use it in GitHub Desktop.
Save zerowidth/1096346 to your computer and use it in GitHub Desktop.
copy a vim buffer or selection as syntax-highlighted RTF to the clipboard
" copy the entire buffer or selected text as RTF
" inspired by https://github.com/dharanasoft/rtf-highlight
" but only uses commands available by default on OS X.
"
" To set html conversion options, :help TOhtml
" And, undocumented, to set the font used,
" let g:html_font="Your Preferred Font"
"
function! CopyRTF(line1,line2)
if !executable('textutil')
echoerr "crap! textutil not found"
return
endif
call tohtml#Convert2HTML(a:line1, a:line2)
silent exe "%!textutil -convert rtf -stdin -stdout | pbcopy"
silent bd!
echomsg "RTF copied to clipboard"
endfunction
command! -range=% CopyRTF :call CopyRTF(<line1>,<line2>)
@zerowidth
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment