'How to format only changed line instead of the whole file in Intelijj IDEA
Intellij format complete file when I use Ctl+Atl+L 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?
Solution 1:[1]
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.
Solution 2:[2]
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.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ersoy |
Solution 3 | Ramy Nasr |