我正在尝试使用 Sublime Text 3 for HTML 中的自动缩进功能。我在 html 中有一些块注释,选择“编辑”>“行”>“重新缩进”可以正常工作,直到遇到块注释。
尝试重新缩进此处的示例:
<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>
结果是这样的:
<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>
有什么想法吗?
我已经在这里记录了这个问题:https://github.com/SublimeTextIssues/Core/issues/1271 https://github.com/SublimeTextIssues/Core/issues/1271
出现此行为的原因是 Sublime Text 默认设置为保留注释缩进。要禁用此功能:
- Install 包控制 https://packagecontrol.io/installation如果尚未安装
- Install PackageResourceViewer https://packagecontrol.io/packages/PackageResourceViewer if it is not already installed:
- 打开命令面板
- Select
Package Control: Install Package
- Select
PackageResourceViewer
- 打开命令面板
- Type
PRV: O
- Select
PackageResourceViewer: Open Resource
- Select
Default
- Select
Indentation Rules - Comments.tmPreferences
- 改变
<true/>
under <key>preserveIndent</key>
to <false/>
- 保存文件
重新缩进现在可以与注释一起正确工作。
我还建议编辑 HTML 缩进规则以忽略注释,这样它就不会根据注释中的标签更改缩进。即否则
<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>
会成为:
<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>
去做这个:
- 打开命令面板
- Type
PRV: O
- Select
PackageResourceViewer: Open Resource
- Select
HTML
- Select
Miscellaneous.tmPreferences
-
Change
<key>scope</key>
<string>text.html</string>
to
<key>scope</key>
<string>text.html - comment</string>
and
|-->
to
(?#|-->)
(这注释掉了结束评论正则表达式)
- Save it
但是,当 ST3 的下一个版本可用时,最好删除您的覆盖,以防它得到正确修复。这样,您将继续获得这些文件的更新,否则您将停留在已保存的版本上。去做这个:
-
Preferences
-> Browse Packages
- 删除
HTML
folder
- 进入
Default
文件夹并删除Indentation Rules - Comments.tmPreferences
file
如果问题在下一个版本中没有得到解决,您可以简单地重新创建这些更改。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)