[IntelliJ IDEA] How to format only local changes when saving the source code

Thing you want to do

I want to be able to execute the following in a batch when pressing cmd + s

--Delete unnecessary import statements --Organize the order of import statements --Only changes that have not been checked in to the repository --Save the code



Format settings

Press cmd + opt + shift + l to display the "Reformat File dialog" Set Scope to "Only VCS changed text", check Optional "Optimize imports", and press "Run" dialog

"Only VCS changed text" can only be set if the project is versioned and there are local changes, so if it is grayed out, check if it is a versioned project and if there are any changes locally. To do.

macro registration

Press Editor-> Macros-> Start Macro Recording and then do the following:

start macro recording

Press Editor-> Macros-> Stop Macro Recording, then save macro as スクリーンショット 2020-06-14 9.43.44.png

Keymap settings

Preferences-> Keymap-> Macros-> Click on the saved macro-> Add Keyboard Shortcut Enter "cmd + s" and OK スクリーンショット 2020-06-14 9.45.59.png

Recommended Posts

[IntelliJ IDEA] How to format only local changes when saving the source code
[IntelliJ IDEA] How to automatically add final when saving a Java file
[Docker] How to build when the source code is bind-mounted on the container
When reading the source code
How to apply C code format from the command line
The secret to the success of IntelliJ IDEA
How to solve the font specification problem dedicated to using IntelliJ IDEA (Win x64)
How to delete the database when recreating the application
[Java] Memo on how to write the source
[Java] How to get the URL of the transition source
How to implement UICollectionView in Swift with code only
How to use java non-standard library on IntelliJ IDEA
[IntelliJ IDEA] How to display code completion candidates without distinguishing between uppercase and lowercase letters
How to decompile apk file to java source code with MAC
How to set chrony when the time shifts in CentOS7
Uppercase only the specified range with substring. (How to use substring)
Specify the character code of the source when building with Maven
How to cure the time dilation when launching Japaneseized Kibana
How to get the log when install4j does not start