How to format only changed line instead of the whole file in Intelijj IDEA

huangapple go评论87阅读模式
英文:

How to format only changed line instead of the whole file in Intelijj IDEA

问题

Intellij使用<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>L</kbd>组合键进行代码格式化,路径为菜单code->Reformat Code。这会在Git提交中生成整个文件的差异。我希望只格式化我修改过的代码,而不是整个文件。有什么方法可以实现吗?

英文:

Intellij format complete file when I use <kbd>Ctl</kbd>+<kbd>Atl</kbd>+<kbd>L</kbd> for from menu code-> Reformat Code. This generates whole diff in git commit. I want to format only the code I have changed not the whole file. How can I do it?

答案1

得分: 12

如果您的文件受版本控制,另一个选项可能是从重新格式化对话框模态中选择“仅应用 VCS 更改的文本”。

正如在文档中所述:

如果选中了此复选框,则重新格式化将仅应用于在本地已更改但尚未检入到存储库的文件。
此复选框仅适用于受版本控制的文件。

How to format only changed line instead of the whole file in Intelijj IDEA

英文:

If your file is under version control, another option could be selecting Only VCS changed text from the Reformat dialog modal.

As it stated in the documentation

> If this checkbox is selected, then reformatting will apply only to the files that have been changed locally, but not yet checked in to the repository.
This checkbox is only available for the files under version control.

How to format only changed line instead of the whole file in Intelijj IDEA

答案2

得分: 4

你需要选择您想要格式化的代码部分(在您的情况下,是已编辑的代码)。然后按下 Ctrl+Alt+L

您可以在这里找到更多信息:链接

How to format only changed line instead of the whole file in Intelijj IDEA

英文:

You have to select the portion of the code you'd like to format (in your case, the edited code). And then press Ctrl+Alt+L.

You can find more info here.

How to format only changed line instead of the whole file in Intelijj IDEA

答案3

得分: 4

如果对任何人有帮助的话,在PhpStorm中有一个选项位于“工具 > 保存时执行的操作”,允许你在保存时重新格式化代码。该选项使你能够仅重新格式化已更改的行。

这实际上允许你通过按下 cmd + s 来仅重新格式化已更改的行。

How to format only changed line instead of the whole file in Intelijj IDEA

英文:

In case this is helpful to anyone, there is an option in PhpStorm under "Tools > Actions on Save" that allows you to reformat code on save. The option allows you to only reformat changed lines.

This effectively allows you to reformat changed lines only by pressing cmd + s

How to format only changed line instead of the whole file in Intelijj IDEA

huangapple
  • 本文由 发表于 2020年7月24日 17:46:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63071061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定