How do I run rustfmt
automatically when I save a file in IntelliJ or CLion?
Asked
Active
Viewed 3,804 times
2 Answers
4
Make sure you have
File Watchers
plugin viaPreferences -> Plugins -> Installed
. If it's not installed, go to theMarketplace
tab and search forFile Watchers
, install it, and restart your IDE.Go to
Preferences -> Tools -> File Watchers
.Add a new watcher and name it
rustfmt
.Configure the watcher by following the screenshot below. Enter the path to
rustfmt
into theProgram
field; it can be found in yourCargo bin directory
.
If you don't know where
Cargo bin directory
directory is, typewhich rustfmt
in your terminal and copy the path. If you still can't find it, make sure you followed the instructions in Installing Rust.

bit2pixel
- 1,122
- 8
- 8
-
You can add `$FILE_PATH$:$LINE$:$COLUMN$` to "Output filters" to get line highlighting too. Can optionally set "show console" to never if you only want to see line highlighting on errors and not the console output. Note that you can also run rustfmt using a setting in the rust plugin now, but it's been buggy lately so I've been using this instead. – Paul Hansen Nov 30 '22 at 03:26