IntelliJ IDEA使用技巧,复制字符串连接文本到剪切板

比如有以下代码,字符串中是一个查询男生、女生人数的 sql

public class Test {

    public static void main(String[] args) {
        // 查询男生、女生人数
        String sql = "select sex,count(*)" +
                "from student" +
                "group by sex;";
    }

}

image.png

如果我想复制出 sql,一般的做法是先复制出以下内容:

"select sex,count(*)" +
                "from student" +
                "group by sex;"

然后再删除双引号和加号,得到需要的内容

select sex,count(*) from student group by sex;

这样做比较麻烦,使用 idea 有更简便的方法

技巧

将光标置于字符串的值处,然后按Alt + Enter(Mac 是 option + return) ,选择 Copy String Concatenation Text to the Clipboard

image.png

复制结果如下,它会删除所有的 "+ ,注意它不会将其放在1行上,还是会有3行,但已经很方便了。

select sex,count(*)
from student
group by sex;

参考

Copying a concatenated constant to the clipboard

串接(Concatenation)- wikipedia

posted @ 2020-10-30 00:50  高行行  阅读(1591)  评论(0编辑  收藏  举报