Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to align javascript's equals sign in webstorm

all

when i config my Webstorm9 settings like this ,it turns out that the sample code in the right aligns the equals sign properly

settings

but when i formatting my javascript code in the editor it doesn't work,it still shows

results

and what i want is align the equals sign

enter image description here

anyone who can take a look?

-------EDIT------

maybe i misunderstand the checked option,but i copy the sample code to my editor then reformat it, oh,bad result..

sample code

like image 517
fuye Avatar asked Jan 09 '15 03:01

fuye


4 Answers

In PHPStorm 2017 (and, I assume, by extension WebStorm) that behavior can be achieved by:

  1. going to Settings > Editor > Code Style > JavaScript
  2. Wrapping and Braces tab
  3. scroll down to Variable declarations and set Align to When Grouped

Additionally, setting Variable declarations to Wrap always will result in this when reformatting:

enter image description here

Update: unchanged in version 2018 and in WebStorm/PHPStorm version 2019, the steps I described above still work the same.

like image 120
Herve Avatar answered Nov 18 '22 11:11

Herve


In Webstorm 10,

  1. Go to Settings> Editor> Code Style > JavaScript

  2. Go to the "Other" tab and check "Align multiple 'var' statements and assignment" and click Ok.

  3. Go to Code > Reformat code (Ctrl + Alt + L)

Voila!

like image 32
Hudvoy Avatar answered Nov 18 '22 11:11

Hudvoy


Update for WebStorm 2017.3

Apparently, since version 2017.3, the Other tab has been removed from Code Style > JavaScript.

Now you have a couple of alignment options under the Wrapping and Braces tab (scroll down to the bottom):

It took me a while to figure this out, hope this helps

like image 3
Qualiture Avatar answered Nov 18 '22 10:11

Qualiture


Update for Webstorm 2016.1

The Preferences Menu

@Hudvoy still has the right answer for this. I've updated with a visual of where you need to look in Webstorm 2016.1

like image 2
Joseph Casey Avatar answered Nov 18 '22 12:11

Joseph Casey