Here's some sample code I have, currently I'm set to only indent using 4 spaces at a time. Is there a way to highlight a block of javascript and press a single button or menu option to format it nicely like so:
Before:
app.get('/csvtest', function (req, res) { MyModel.find(function (err, mymodel) { if (!err) { var csv = []; _.each(mymodel, function(obj) { csv.push(obj['mymodel']); }); res.send(csv.join()); } else { console.log(err); } }); });
After:
app.get('/csvtest', function (req, res) { MyModel.find(function (err, mymodel) { if (!err) { var csv = []; _.each(mymodel, function(obj) { csv.push(obj['mymodel']); }); res.send(csv.join()); } else { console.log(err); } }); });
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.
by pressing ctrl+f12, it will reindent your file to a tab size of 4. if you want a different tab size, you just change the "value" number.
Sublime Text 2 allows you to convert tabs to spaces in existing files manually (View -> Indentation -> Convert indentation to spaces). However, this can be done automatically when saving the file.
Command Palette: Ctrl+Shift+P → Wrap Paragraph Justified at Ruler. Shortcut: Alt+Shift+Q.
Here is a tool for this. Found it on the sublime forums.
jsFormat
and hit enterCtrl
+ Alt
+ f
to formatYou could give JsFormat a go. ctrl+alt+f formats the selected text.
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