27

Is there a simple way to copy syntax-coloured code block as rtf in intellij IDEA?

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
qwazer
  • 7,174
  • 7
  • 44
  • 69

5 Answers5

36

UPDATE: there is now a new plug-in for this: 'Copy' on steroids that is maintained by JetBrains.


There is no way to copy colored code block from IDEA directly.

A workaround is to use File | Export to HTML, then open HTML in a browser, then copy from the browser window and paste into Wordpad or MS Word.

Another and more faster way is to install the Copy as HTML plug-in in Settings | Plugins:

Copies a snippet of code as html

  • Adds menu items "Copy as HTML" to main menu and editor popup. Will copy the current selection or the complete editor buffer. Currently only works if focus is in editor (for example won't work in project tree).
  • Preserves more formatting than the built-in HTML export.
  • HTML is only a snippet (without html and body tags) meant to be inserted into a complete HTML document.
  • Currently HTML format is fixed and uses CSS a lot.
  • Options: unindent, add border, padding, line numbers, tabs to spaces conversion, include editor's warning and error highlighting (see IDE Settings -> Copy as HTML).
  • Reuses the editor "Show Line Numbers" setting (see Idea's "View" menu).
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • thanks, i know this way, but i prefer using such method: 1) copy to notepad++ 2) apply syntax highlighting 3) copy with nppexport plugin to clipboard as rtf – qwazer Feb 03 '11 at 10:33
  • If you knew this method, plus another method, you should have replied yourself and accepted the reply as correct. – CrazyCoder Feb 03 '11 at 11:28
  • 1
    The Version of the plugin linked doesn't work with IDEA11. A fixed version is available at: http://youtrack.jetbrains.com/issue/WI-8163 I didn't edit CrazyCoder's answer because his URL still points to the official build where this fix should eventually be merged into. – Dan Is Fiddling By Firelight Mar 21 '12 at 18:23
  • Both JetBrains and Copy as HTML plugins work with 12, and both are nice, but I prefer JetBrain's output. They're slick. – Antony Stubbs Aug 23 '13 at 19:20
  • 1
    Neither of these seem to work with IntelliJ 12 or 13 and Keynote 6. This is the only solution I found that works: https://gist.github.com/jimbojsb/1630790 – Matt Raible Feb 26 '14 at 05:50
  • @MattRaible, that was very useful. And there is a `darcula` theme for highlight [**here**](https://gist.github.com/jvandijk/395f4a41cc56955fee0a) which, in my limited tests, worked quite well. I copied that to `/usr/local/Cellar/highlight/3.30/share/highlight/themes/` and then used something like this `highlight -lO rtf -s darcula -k 'Courier' -K 11 input.sql > output.rtf` (For description of the options see [**this**](https://developer.atlassian.com/blog/2015/08/beautiful-presentations-with-highlight/) ) – Ashutosh Jindal Aug 31 '16 at 20:06
7

IntelliJ IDEA 15

By default, you can copy rich text from IntelliJ to Microsoft Word (for example).

This feature can be found in File > Settings... > Editor > General > Rich-text copy > Copy as rich text by default

enter image description here

You can also change the color scheme only for the copy-paste operation (your current scheme won't be affected).

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
6
  1. Go to https://gist.github.com/
  2. Copy code from IntelliJ to the new private gist;
  3. Save it, copy colorful code from the browser to wherever you want;
  4. Delete the gist.
Sotomajor
  • 1,386
  • 11
  • 15
3

Use external tool notepad++ 1) copy code snippet to notepad++ 2) apply syntax highlighting 3) copy with nppexport plugin to clipboard as rtf

qwazer
  • 7,174
  • 7
  • 44
  • 69
0

If you're on a mac and like TextMate, here's a great way to copy styled code from TextMate: https://github.com/bblimke/copy-with-style-tmbundle

It's not as convenient as doing it directly from IntelliJ, but it's a bit more convenient than using gist or pastebin. Also, unlike the Copy as HTML Plugin for IntelliJ, this solution actually works at the time of this writing.

emmby
  • 99,783
  • 65
  • 191
  • 249