Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Forked from zerowidth/copy_rtf.vim
Created April 12, 2012 15:42
Show Gist options
  • Select an option

  • Save cstrahan/2368369 to your computer and use it in GitHub Desktop.

Select an option

Save cstrahan/2368369 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>)
@j3j3
Copy link
Copy Markdown

j3j3 commented May 16, 2012

What an amazing gist.

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