Save actions in IntelliJ IDEA

前端 未结 7 677
挽巷
挽巷 2020-12-24 10:13

The only thing that exists in Eclipse, which I miss in IntelliJ IDEA is \"save actions\" - possibility to do some actions (usually formatting) when a file is saved.

相关标签:
7条回答
  • 2020-12-24 10:45

    You may use a Macro to simulate save actions:

    Edit --> Macros --> Start Macro Recording

    ==> now execute all actions you need (e.g. reformat, rearrange, optimize imports)

    Edit --> Macros --> Stop Macro Recording

    Give your new Macro a name. You can also assign a shortcut to your macro. Just enter it's name in the settings search and you will find it under Macro.

    Have fun!

    0 讨论(0)
  • 2020-12-24 10:46

    See here: Intellij reformat on file save.

    The answer I linked to explains in a few easy steps how to record a macro for optimize imports and reformat and then run that macro when you save your files (bind it to Ctrl+S).

    0 讨论(0)
  • 2020-12-24 10:49

    I think it might break the philosophy that JetBrains have. Nothing should be done unless the user/developer requests it (and no Wizards). So you are stuck with Ctrl-Alt-L or just indent Ctrl-Alt-I. I personally only use the latter since the code usually formats itself as you type.

    Also Idea saves files as soon as you leave window or (I think) wait for a certain time, this might really mess up things.

    0 讨论(0)
  • 2020-12-24 10:50

    Had the same problem, but Save Actions were not flexible enough. I went for File Watchers plugin which allows for running custom programs each time a file of a given type changes.

    0 讨论(0)
  • 2020-12-24 10:58

    There is something similar - possibility to do some actions, when a file is committed. In a file commit window there is a "Before commit" section which contains checkboxes like "optimize imports", "Reformat code", etc.

    0 讨论(0)
  • 2020-12-24 11:06

    You will need to Install Save Actions plugin for Intellij IDEA

    1. Click: ctrl+shift+a
    2. Type: Plugins
    3. Click: enter Plugins
    4. Click: Browse repositories
    5. Type: Save Actions to search field
    6. Click "install plugin" after you found it
    7. Restart intellij idea

    Save actions now work. You can configure them in File -> Settings -> Other settings

    0 讨论(0)
提交回复
热议问题