最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

intellij idea - How to revert auto formatting changed lines and save the file - Stack Overflow

programmeradmin2浏览0评论
  • Actions on save -> checked,
  • Reformat changed lines -> checked
  • Optimize imports -> checked.

This works excellently most of the time, but sometimes I want my own formatting to remain.

I seem to remember that if you do Cmd + Z immediately after save, the IDE would revert the auto code formatter and save the file (maybe from Eclipse?) But IntelliJ undoes the reformatting and marks the file as unsaved, when saving it will do the reformat again. I press Cmd + Z again, code is how I want it, Cmd + S auto format again. I failed to find a way out of this loop, unless I disable "reformat changed lines" from "actions on save". But most of the time I want that.

How can I undo the auto reformat and save the file? I don't want to use formatter markers.

  • Actions on save -> checked,
  • Reformat changed lines -> checked
  • Optimize imports -> checked.

This works excellently most of the time, but sometimes I want my own formatting to remain.

I seem to remember that if you do Cmd + Z immediately after save, the IDE would revert the auto code formatter and save the file (maybe from Eclipse?) But IntelliJ undoes the reformatting and marks the file as unsaved, when saving it will do the reformat again. I press Cmd + Z again, code is how I want it, Cmd + S auto format again. I failed to find a way out of this loop, unless I disable "reformat changed lines" from "actions on save". But most of the time I want that.

How can I undo the auto reformat and save the file? I don't want to use formatter markers.

Share Improve this question edited Mar 14 at 7:35 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 14 at 7:29 Bogdan PopBogdan Pop 1016 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You need to do the setting to remove that behavior first, that you can find at

Settings > Tools > Actions on Save

Uncheck the Reformat code , you can pick some file types to apply this or not.

发布评论

评论列表(0)

  1. 暂无评论