Reputation: 18675
I'm looking for a way to auto-format my code in the WebStorm IDE?
Upvotes: 104
Views: 128822
Reputation: 50
Reference https://www.jetbrains.com/help/webstorm/command-line-formatter.html#options
Format files from the command line
# my case in mac
➜ bin pwd
/Users/xxx/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/231.8770.64/WebStorm.app/Contents/bin
➜ bin ./format.sh -s ~/Default.xml -r /xxxx
Upvotes: 1
Reputation: 154
A slight correction on the answer based on Code reformatting on save in PhpStorm or other jetbrains ide This answer is basically correct, but you need to create a custom keybinding for Save All
in order for it to work, and the keybinding given for Windows (or Linux), Ctrl+Alt+S is used to open the settings dialog which could have unwanted consequences.
Save All
key bindingKeymap
-> Main Menu
-> File
->Save All
Remove Ctrl+S/Cmd+S
Add Keyboard Shortcut
OK
on the shortcut window and settings window.Edit
-> Macros
-> Start Macro Recording
Format-save
Keymap
-> Main Menu
-> Edit
->Macros
->Format-save
Add Keyboard Shortcut
OK
on the shortcut window and settings window.And you're all set!
Upvotes: 1
Reputation: 477
>
Marketplace.Save Actions
into search field.Reformat file
> Press OK button.Visit Plugin Homepage
Upvotes: 2
Reputation: 5624
It is possible by creating a macro that formats the code and save it, and then bind this macro to Ctrl+S shortcut. (Mac: Cmd+S)
This answer was posted for phpStorm and it is equally valid for WebStorm. A modified version of answer is as follows:
Record the macro
Assign Ctrl+S to "Format and Save"
That's it.
Upvotes: 109
Reputation: 311
"Save Actions" plugin can format code when saving.
Install plugin:
File -> Settings -> Plugins -> Browse repositories;
Config plugin:
File -> Settings -> Other Settings
Upvotes: 30