问题
Previously I used Eclipse for PHP and Java development, and I liked the command Ctrl + i
to automatically indent the code.
Now am I using Aptana Studio that is based on Eclipse, for JavaScript development. I would like to automatically indent my JavaScript code, but Ctrl + i
deletes all my code. Is there any other command that automatically indent JavaScript code in Aptana Studio?
回答1:
The Studio does not have this feature yet. You can add a feature request here: https://aptana.lighthouseapp.com/projects/35272-studio/tickets/new
Ctrl+Shift+F will format your entire file, as Tim suggested. You can control some of the formatter settings through the preferences at 'Window -> Preferences -> Aptana Studio -> Formatter'
回答2:
Maybe you mean format feature CTRL+SHIFT+F
?
回答3:
I've just updated to Aptana Studio 3.0.9 and it now seems to be able to format specific (selected) lines of JavaScript, HTML and CSS, in some circumstances. The default key binding for me was something odd so I changed the key binding to CTRL+I
in Preferences > General > Keys
.
If no code is selected then Source > Format
seems to always reliably format the entire file. The behaviour of Source > Format
on selections differs depending on the type of code you're editing:
JavaScript
- Editing a .js file:
Source > Format
appears to work as you'd expect: if you select a few lines of code thenSource > Format
will correctly indent just the selected lines of code. - Editing JavaScript within HTML: Formatting JavaScript within an HTML file appears to work most of the time but sometimes fails; I have not been able to discover the rules.
HTML
- If you select a chunk of HTML, AND IF the top line of that selection is correctly indented ALREADY, AND IF the selection does not include any unclosed elements then
Source > Format
will do the right thing. - Otherwise
Source > Format
seems to act unpredictably with HTML.
CSS
- Editing a .css file:
- works fine if I select an entire rule (i.e. including all of
selector { declaration block; }
) (in which case Aptana formats just that rule). - But if my selection does not include the entire rule then I get an error.
- works fine if I select an entire rule (i.e. including all of
- Editing css within HTML:
- If part of the CSS is selected within a
<style>
block thensource > format
will format all the css within that<style>
block. There seems to be no way to format just a few lines of css within html.
- If part of the CSS is selected within a
Unless anyone points out that this post contains fatal flaws within the next few days, I'll post a feature request at https://jira.appcelerator.org to ask for consistency in formatting behaviour across code types (a quick look at the existing feature and bug requests suggests that code formatting has received a considerable amount of attention recently).
update 19/3/2012 I've posted this bug on the JIRA: https://jira.appcelerator.org/browse/APSTUD-4516
回答4:
I was having the same issue and stumbled across this site: jsbeautifier You might wanna check it out. Worked fine for me ;)
来源:https://stackoverflow.com/questions/6138115/how-to-automatically-indent-the-javascript-code-in-aptana-studio