Reputation: 6010
Related but not identical question: Sublime Text indentation behavior.
I have seen many videos in which after the autocompletion of an HTML tag, pressing enter automatically results in the closing tag appearing two lines, and the cursor being properly indenting on the second line, between the opening and closing tabs.
In my situation, the autoindent function in Sublime Text 2 seems to be working poorly. Here is exactly what happens (as can be seen in the below gif).
That is 7 keystrokes, which should under normal circumstances be 2 keystrokes. This applies to every tag I use in HTML, and it is getting extremely frustrating.
Note how this only happens in HTML. Below is a GIF of the autoindent function working properly (with only one keystroke) in CSS.
I have very few, unrelated packages installed on ST2. Here are the contents of my Settings - User file.
{
"color_scheme": "Packages/Theme - Spacegray/base16-ocean.dark.tmTheme",
"ignored_packages":
[
"Vintage"
],
"theme": "Spacegray.sublime-theme",
"margin": 0,
"fold_buttons": false,
"draw_minimap_border": true,
"auto_complete_commit_on_tab": false
}
Why does my autoindent function in Sublime Text 2 do this? And how can I fix it?
EDIT: @Shomz has indicated that this is how HTML indenting works by default. Is there any plugin/workaround I can use to get the desired effect?
Upvotes: 1
Views: 1346
Reputation: 102842
Try installing the Emmet
plugin, previously known as Zen Coding. It allows you to enter HTML using a CSS selector-like syntax, so for example
html>body>div.main
and pressing Tab gives you
<html>
<body>
<div class="main">|</div>
</body>
</html>
where the |
is the cursor position. More importantly, for your present question, just typing body
Tab gives you
<body>
|
</body>
just like you were looking for. See the Emmet docs for all the details.
Upvotes: 1