java - Eclipse - 包含选择而不是替换

标签 java eclipse

在 Eclipse 中,当我选择部分文本并按任意键时,整个选择被替换。 我想知道如何制作它,而不是替换文本,而是将按下的键添加到选择的两端,就像在 visual studio 代码中发生的那样。

例子:

System.out.println(HelloWorld);

选择 Hello World

System.out.println(HelloWorld);

然后按"按钮。代码将变为

System.out.println(");

我可以配置 IDE 以便它改为将其更改为

System.out.println("HelloWorld");

有一个像这样的问题已经回答了,但是考虑到这个问题已经有 7 年了,而且版本很旧,而且考虑到那个问题的答案是一种解决方法,我想知道是否有使它更好地工作的任何新插件或配置

最佳答案

据我所知,你想要做类似 this 的事情?

Go to Java > Editor > Templates and add a new template, e. g. called quote, as follows:

"${word_selection}"${cursor}

Then, in the editor, write a text you want to quote, select it, press Ctrl+Space, type quote and hit Return. The highlighted text should be quoted now.

If you don't get template proposals when pressing Ctrl+Space, make sure you have them checked in Java > Editor > Content Assist > Advanced.

Just tried it and it works for me!

您可以将此方法用于其他事情,例如 (${word_selection})${cursor} 用于括号或 '${word_selection}'${cursor}用于单引号。

关于java - Eclipse - 包含选择而不是替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51991652/

相关文章:

java - 无法解析 intellij 中的符号 jsonobject

java - liferay "Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH"用于图像(即使是来自 DLFileEntry 对象的小图像)

java - Spring Boot 不绑定(bind)到 Tomcat 端口

java - Eclipse 插件 : Custom icon for a Marker

java - Spring/Eclipse 项目突然记录一切

java - 当我创建新内容时不要生成 TODO eclipse

Java跳过序列中的数字

java - 无法在 Spring Tools 4/Eclipse 中安装 org.eclipse.ajdt.ui.nature

jar 文件中的 javax/mail/MessagingException 但在 Eclipse 中工作的代码相同

java - Java中的Varargs到ArrayList问题