Last active
August 29, 2015 13:56
-
-
Save jferris/8924087 to your computer and use it in GitHub Desktop.
Copy a range from Vim as rich text for pasting into Keynote
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
| #!/usr/bin/env ruby | |
| # Save this somewhere on your path and make it executable | |
| lines = STDIN.readlines | |
| min_indent = lines.inject 100 do |result, line| | |
| if line.strip.length == 0 | |
| result | |
| else | |
| length = line.match(/^ */)[0].length | |
| length < result ? length : result | |
| end | |
| end | |
| lines.each do |line| | |
| if line.strip.length == 0 | |
| puts | |
| else | |
| puts line.slice(min_indent, line.length) | |
| end | |
| end |
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
| " Requires highlight: | |
| " http://www.andre-simon.de/doku/highlight/en/highlight.php | |
| function! CopyRTF(options) range | |
| let command = "!cat % | " | |
| if a:firstline | |
| let command = command . "sed -n " . a:firstline . "," . a:lastline . "p | clean_indent | " | |
| endif | |
| let command = command . "highlight -O rtf -kInconsolata -K40 --no-trailing-nl --syntax=" . &filetype . " --style=fine_blue " . a:options . " | pbcopy" | |
| exec ":silent :" . command | |
| endfunction | |
| command! -nargs=0 -range CopyRTF <line1>,<line2>call CopyRTF("") | |
| command! -nargs=0 -range CopyRTFWithLines <line1>,<line2>call CopyRTF("--line-numbers --line-number-length=2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment