Can IntelliJ IDEA automatically format a code block after finishing it?

荒凉一梦 提交于 2019-12-23 17:42:34

问题


Some IDEs offer the feature to automatically format a line or block of code after finishing it e.g. by writing the closing curly or semicolon. I find it hard to believe that IDEA does not offer this kind of feature. Or does it?

If you know how to turn it on - or if I maybe need some plugin - let me and the world know, please!


回答1:


There is no automatic reformat feature, related requests:

  • IDEABKL-5806 Automatically trigger code formatter on file save
  • IDEABKL-475 Hard (auto-)reformat code

See also my answer to the similar question with the Complete Current Statement workaround.




回答2:


If it's a single line, you can use the Complete Current Statement action (which adds a closing bracket, semi-colon, and so on) with ctrl-shift-enter - this seems to reformat the whole line.

Otherwise, you can obviously rebind ctrl-w and ctrl-alt-l (to reformat selected text) or just ctrl-alt-l (reformat whole file) to faster / easier keybindings so that you can quickly reformat whenever you want to.



来源:https://stackoverflow.com/questions/20631065/can-intellij-idea-automatically-format-a-code-block-after-finishing-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!