As I type the following javascript code (exact keystrokes):
myObject
.doSomething()
.doSomethingElse();
I'd expect it to automatically become the following...
myObject
.doSomething()
.doSomethingElse();
... as would any other programmer, right?
How do I enable this, and why isn't it enabled by default?
That's quite simple in Sublime. Just Ctrl+Shift+P (or Command+Shift+P on MacOS) to open the tools pallet, type reindent , and pick Indentation: Reindent Lines . It should reindent all the file you are in, just remember to save before running the command, or it may not appear.
Ensure tab width is set to 2. Convert your 2-space indentation to tabs, switch to tab width 4, and then convert the indentation back to spaces.
You can use ctrl+ ] to indent a line (or highlighted block), and ctrl + [ to unindent. On OSX this is cmd + ]/[ . at least on the mac version tab & shift-tab work on whole lines and the position of the cursor has no influence on it.
You can use Sublime Code formatter with support JavaScript/JSON Beautifier, this link will show you how to usage this plugin.
Or another way is to insert your code inside Key Bindings - User
file:
{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With