Java 如何在 IntelliJ IDEA 中的参数列表中调用方法后添加分号?

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

How to add semicolon after method call when inside parameter list in IntelliJ IDEA?

javaintellij-idea

提问by digiarnie

I'm finally making the voyage back to IntelliJ via Eclipse. Currently my Eclipse is set up so that if I currently have a statement such as this (where ^ denotes where my cursor currently sits):

我终于要通过 Eclipse 回到 IntelliJ 了。目前,我的 Eclipse 已设置,因此如果我目前有这样的语句(其中 ^ 表示我的光标当前所在的位置):

foo.bar("hello"^)

and I hit the semi-colon (;) key, it will automatically put the semi-colon at the end of the statement:

然后我按分号 (;) 键,它会自动将分号放在语句的末尾:

foo.bar("hello");

Currently IntelliJ does this:

目前 IntelliJ 这样做:

foo.bar("hello";)

Meaning I will have to explicitly type the closing bracket before typing the semi-colon.

这意味着我必须在输入分号之前明确输入结束括号。

Not a huge problem obviously but I have found myself putting the semi-colon in the wrong place a few times today as I make the transition back to IntelliJ and thought that it may be more efficient (for both my fingers and brain) not to have to type the closing bracket.

显然不是一个大问题,但我发现自己今天几次将分号放在错误的位置,因为我过渡回 IntelliJ 并认为它可能更有效(对于我的手指和大脑)不键入结束括号。

采纳答案by Noel M

For Windowsor Linuxusers, Ctrl+Shift+Enter.

对于的WindowsLinux的用户,Ctrl+ Shift+ Enter

For macOS/OS Xusers, ? Command+? Shift+Enter.

对于Mac系统/ OS X用户,? Command+ ? Shift+ Enter

That finishes the statement you're currently writing. Try it in a few different situations, like in if statements, for loops etc, and you'll see that it'll complete the line and open some curly braces for you if necessary.

您当前正在编写的语句到此结束。在几种不同的情况下尝试它,例如在 if 语句、for 循环等中,您会看到它会完成该行并在必要时为您打开一些花括号。

回答by LimaNightHawk

You can adda keymap of your own. I added Ctrl+;to my Keymaps for the "Complete Current Statement" action. This saved me an extra key stroke and made it a little bit more intuitive.

您可以添加自己的键盘映射。我为“完成当前语句”操作在我的键盘映射中添加了Ctrl+ ;。这为我节省了额外的击键次数,并使其更加直观。

  1. Go to Settings > Keymap
  2. In the search box, enter "Complete Current Statement".
  3. Right-click on the entry and select "Add Keyboard shortcut"
  4. With the First Strokefield hightlighted, enter your key combination. E.g., Ctrl+;, which will display as Ctrl+Semicolon
  5. Click OK, and OKto save and exit.
  1. 转到设置 >键盘映射
  2. 在搜索框中,输入“完成当前语句”。
  3. 右键单击该条目并选择“添加键盘快捷键”
  4. 突出显示First Stroke字段,输入您的组合键。例如,Ctrl+ ;,它将显示为Ctrl+Semicolon
  5. 单击OK、 和OK保存并退出。

You can opt to remove or keep the existing mapping. Should look something like this when you're done:

您可以选择删除或保留现有映射。完成后应该看起来像这样:

enter image description here

在此处输入图片说明

回答by Hamidreza Sadegh

if you want always have it just do this

如果你想永远拥有它就这样做

enter image description here

在此处输入图片说明