I'm trying to use the auto-indentation feature in Sublime Text 3 for HTML. I've got some block comments in the html and selecting Edit>Line>Reindent works until it hits a block comment.
Try to reindent the example here:
<html>
<head>
<title>Testing Indent</title>
</head>
<body>
<table>
<tr>
<td>
Cell 1
</td>
</tr>
<tr>
Cell 2
<!--Block Comment Here
And a Little More Here
-->
</tr>
</table>
</body>
</html>
and it turns out like this:
<html>
<head>
<title>Testing Indent</title>
</head>
<body>
<table>
<tr>
<td>
Cell 1
</td>
</tr>
<tr>
<td>
Cell 2
<!--Block Comment Here
And a Little More Here
-->
</td>
</tr>
</table>
</body>
</html>
Any thoughts?
To solve, click on the "Tab Size" at the bottom of the editor, and choose "Convert Indentation to Tabs". Show activity on this post. You start using a text editor that allows you to show indents, and you become consistent about using spaces instead of tabs, and you enforce that in your editor. Yeah.. you're right.
Changing indentation for the current bufferIndentation settings are available from the View/Indentation menu. Selections made here are applied to the current buffer only.
Go to Home and select Line and Paragraph Spacing > Line Spacing Options at the bottom of the menu. The Paragraph dialog box opens. On the Indents and Spacing tab, select the options you want, and click OK. The Paragraph dialog box options are described in Adjust indents and spacing.
The indentation error can occur when the spaces or tabs are not placed properly. There will not be an issue if the interpreter does not find any issues with the spaces or tabs. If there is an error due to indentation, it will come in between the execution and can be a show stopper.
I have logged the issue here: https://github.com/SublimeTextIssues/Core/issues/1271
The reason for this behavior is because Sublime Text, by default, is set to preserve the indentation of comments. To disable this:
Package Control: Install Package
PackageResourceViewer
PRV: O
PackageResourceViewer: Open Resource
Default
Indentation Rules - Comments.tmPreferences
<true/>
under <key>preserveIndent</key>
to <false/>
Reindentation will now work correctly with comments.
I would also recommend to edit the HTML indentation rules to ignore comments, so that it doesn't change indentation based on tags in comments. i.e. otherwise
<html>
<head>
<title>Testing Indent</title>
</head>
<body>
<table>
<tr>
<td>
Cell 1
</td>
</tr>
<tr>
Cell 2
<!--
Block Comment Here
<td>
And a Little More Here
</td>
-->
</tr>
</table>
</body>
</html>
would become:
<html>
<head>
<title>Testing Indent</title>
</head>
<body>
<table>
<tr>
<td>
Cell 1
</td>
</tr>
<tr>
Cell 2
<!--
Block Comment Here
<td>
And a Little More Here
</td>
-->
</tr>
</table>
</body>
</html>
To do this:
PRV: O
PackageResourceViewer: Open Resource
HTML
Miscellaneous.tmPreferences
Change
<key>scope</key>
<string>text.html</string>
to
<key>scope</key>
<string>text.html - comment</string>
and
|-->
to
(?#|-->)
(this comments out the closing comment regex)
However, when the next release of ST3 is available, it might be a good idea to then delete your overrides, in case it is fixed properly. This way, you will continue to get updates to these files, otherwise you will be stuck with the versions you have saved. To do this:
Preferences
-> Browse Packages
HTML
folderDefault
folder and delete the Indentation Rules - Comments.tmPreferences
fileIf the problem wasn't fixed in the next build, you can simply recreate these changes.
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