Remove trailing whitespace on save in IntelliJ IDEA 12

前端 未结 4 1429
梦谈多话
梦谈多话 2021-02-02 04:52

Is it possible to remove trailing whitespace automatically on save in IntelliJ IDEA? I know there are some workarounds, for example, using git to trim the whitespace on commit.

4条回答
  •  粉色の甜心
    2021-02-02 05:36

    Add an external tool. As the Program pass /usr/bin/sed (may be different on your box, run which sed to locate) and insert the -i 's/[[:space:]]\+$//' $FilePath$ in the Parameters. Overall the command that you want IntelliJ to run is,

    /usr/bin/sed -i 's/[[:space:]]\+$//' 
    

    This sed will remove the trailing whitespace, and overall the effect will be very similar to git. Next you can add a keyboard shortcut for your new external tool entry, but I am not sure whether it is possible to run anything on save.

提交回复
热议问题