带有语法高亮显示的 Eclipse 复制代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8386299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse copy code with syntax highlighting
提问by Alessandro Pezzato
I'm writing a document of programming guidelines for my developers team. I use MS Word. We work with Eclipse CDT(C++). I need to copy-paste C++ code with syntax highlightingfrom Eclipseto Word. I've tried Notepad++and it can export text with syntax highlighting, but it's highlighting is limited to basic syntax (it doesn't know about defined class, enum etc...). Eclipse syntax highlighting is very powerful and I wish to export directly from Eclipse to Word using it's syntax highlighting.
我正在为我的开发团队编写一份编程指南文档。我使用MS Word。我们使用Eclipse CDT(C++)。我需要将带有语法突出显示的 C++ 代码从Eclipse复制粘贴到Word。我试过Notepad++,它可以导出带有语法突出显示的文本,但它的突出显示仅限于基本语法(它不知道定义的类、枚举等......)。Eclipse 语法突出显示非常强大,我希望使用它的语法突出显示直接从 Eclipse 导出到 Word。
Is there any Eclipse pluginthat achieve this purpose? Or some trickto do it (without taking a screen snapshot)?
是否有任何 Eclipse 插件可以实现此目的?或者一些技巧来做到这一点(不拍摄屏幕快照)?
回答by Mansuro
When you copy the code to word document, you can choose the option "keep source formatting" and the highlighting will be the same as the one in eclipse.
复制代码到word文档时,可以选择“保留源格式”选项,高亮将与eclipse中的相同。
EDIT:
编辑:
As mentioned in the comments below, this won't work on folded code, so you can right click on the line numbers and select Folding > Expand All
正如下面的评论中提到的,这不适用于折叠代码,因此您可以右键单击行号并选择 Folding > Expand All
EDIT 2:Also mentioned in the comments, as of eclipse oxygen, the code is automatically copied with syntax highlighting
编辑 2:在评论中也提到,从 Eclipse 氧气开始,代码会自动复制并突出显示语法
回答by ChrisCantrell
When I copy from Eclipse straight to PowerPoint some of the formatting is messed up. Bold and color seems to "keep going". But if I copy from Eclipse to Word -- and then from Word to PowerPoint (with the keep source formatting CNTRL-K) -- the formatting is correct. I recently upgraded Eclipse to Mars and Office to 2013. I still have to go through Word first.
当我从 Eclipse 直接复制到 PowerPoint 时,一些格式被弄乱了。大胆和色彩似乎“继续”。但是如果我从 Eclipse 复制到 Word——然后从 Word 复制到 PowerPoint(使用保留源格式 CNTRL-K)——格式是正确的。我最近把Eclipse升级到了Mars,Office升级到了2013,还是得先通过Word。
回答by Rusca8
I was trying it too and for some reason not every compile unit would keep the formating.
我也在尝试它,出于某种原因,并非每个编译单元都会保留格式。
After a while I've seen that you also won't get the formating kept if there are parts of the code hidden, so for the ones that cannot make it work with the answers above, just make sure that there are no "+" signs on the left of your code (mine were where the imports at the beggining).
一段时间后,我发现如果隐藏了部分代码,您也不会保留格式,因此对于那些无法使用上述答案的人,只需确保没有“+”代码左侧的标志(我的是在开始时导入的地方)。
回答by Rusca8
Copying of formatting is supported since version 3.2
自 3.2 版起支持格式复制
Note that everythingis copied: highlighting of spelling errors, marked variables/types/etc and underscoring of warnings/errors.
请注意,所有内容都被复制:突出显示拼写错误,标记变量/类型/等,并强调警告/错误。
To avoid that, turn off spell checking, "Mark Occurrences" and "Report problems as you type" respectively.
为避免这种情况,请分别关闭拼写检查、“标记出现次数”和“键入时报告问题”。