复制粘贴时 Eclipse PDT 上的自动缩进

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2469972/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:32:20  来源:igfitidea点击:

Automatic indentation on Eclipse PDT when copy-pasting

eclipseeclipse-pdt

提问by Matthieu Napoli

This is a simple question :

这是一个简单的问题:

Is there any automatic indentation alignment on Eclipse PDT when you do a copy-paste ?

进行复制粘贴时,Eclipse PDT 上是否有任何自动缩进对齐?

Because it doesn't work on my installation (raw copy-paste), but maybe this is because I use tabs instead of spaces, so I want to know if it will work if I switch to spaces.

因为它不适用于我的安装(原始复制粘贴),但也许这是因为我使用制表符而不是空格,所以我想知道如果我切换到空格它是否会起作用。

Thanks

谢谢

采纳答案by Matthieu Napoli

Ok then I guess the answer is : no, this functionnality doesn't exists yet. I've moved to PhpStorm and I'm more than happy.

好的,我想答案是:不,此功能尚不存在。我已经搬到了 PhpStorm,我非常高兴。

回答by Offirmo

Actually, such a function exists now for eclipse CDT. In preferences : C++ -> Editor -> Typing, "when pasting", "adjust indentation".

实际上,现在对于 eclipse CDT存在这样的功能。在首选项中:C++ -> 编辑器 -> 打字、“粘贴时”、“调整缩进”。

Perhaps it is the same for PDT ?

也许 PDT 也是如此?

回答by David Sauter

I don't know specifically about PDT, but normally you can indent code with Ctrl + i, and format code with Ctrl + Shift + f(under Preferences -> Java -> Code Style -> Formatteryou can specify how the formatter should work).

我并不特别了解 PDT,但通常您可以使用 缩进代码Ctrl + i,并使用 格式化代码Ctrl + Shift + f(在Preferences -> Java -> Code Style -> Formatter您可以指定格式化程序的工作方式下)。

You can even select multiple files in the navigator and select Source -> Formatto format several files then.

您甚至可以在导航器中选择多个文件,然后选择Source -> Format格式化多个文件。

回答by Greg

Tony Vermeiren had a suggestion that worked for me (from https://bugs.eclipse.org/bugs/show_bug.cgi?id=351771#c17)

Tony Vermeiren 有一个对我有用的建议(来自https://bugs.eclipse.org/bugs/show_bug.cgi?id=351771#c17

open workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.php.ui.prefs

打开workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.php.ui.prefs

add "smartPaste=false" at the end

在末尾添加“smartPaste=false”

save & restart eclipse

保存并重启eclipse

回答by Sebastian Ax

TLDR: uncheck "C/C++->Editor->Typing->Adjust indentation"

TLDR:取消选中“C/C++->Editor->Typing->Adjust indentation”

Explanation:

解释:

When i copy paste the following:

当我复制粘贴以下内容时:

copyPasteMakredText

复制粘贴标记文本

And "C/C++->Editor->Typing->Adjust indentation" checked

并选中“C/C++->Editor->Typing->Adjust indentation”

enter image description here

在此处输入图片说明

The result is that the second line has unwanted indentation:

结果是第二行有不需要的缩进:

enter image description here

在此处输入图片说明

To fix this just uncheck "C/C++->Editor->Typing->Adjust indentation"

要解决此问题,只需取消选中“C/C++->Editor->Typing->Adjust indentation”

回答by Zoltán Ujhelyi

A similar idea to Davids is the use of Save actions: in the Preferences selecting Java/Editor/Save actions you can define an action to format the java code files during saves. It would solve the paste format problems during the save.

与 Davids 类似的想法是使用 Save 操作:在 Preferences 中选择 Java/Editor/Save 操作,您可以定义一个操作来在保存期间格式化 Java 代码文件。它将解决保存过程中的粘贴格式问题。

If you manage codes with different coding standards, where this formatting might have problems, define multiple formats, on a per-project basis (using the Project properties window).

如果您使用不同的编码标准管理代码,而这种格式可能会出现问题,请在每个项目的基础上定义多种格式(使用项目属性窗口)。