8

我正在尝试使用 Sublime Text 3 for HTML 中的自动缩进功能。我在 html 中有一些块注释,选择 Edit>Line>Reindent 可以工作,直到它遇到块注释。

尝试在此处重新缩进示例:

<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>

有什么想法吗?

4

2 回答 2

21

我在这里记录了这个问题:https ://github.com/SublimeTextIssues/Core/issues/1271

这种行为的原因是因为默认情况下,Sublime Text 设置为保留注释的缩进。要禁用此功能:

  1. 如果尚未安装Package Control ,请安装
  2. 如果尚未 安装PackageResourceViewer ,请安装:
    • 打开命令面板
    • 选择Package Control: Install Package
    • 选择PackageResourceViewer
  3. 打开命令面板
  4. 类型PRV: O
  5. 选择PackageResourceViewer: Open Resource
  6. 选择Default
  7. 选择Indentation Rules - Comments.tmPreferences
  8. <true/>将下更改<key>preserveIndent</key><false/>
  9. 保存文件

重新缩进现在可以与注释一起正常工作。


我还建议编辑 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>

去做这个:

  1. 打开命令面板
  2. 类型PRV: O
  3. 选择PackageResourceViewer: Open Resource
  4. 选择HTML
  5. 选择Miscellaneous.tmPreferences
  6. 改变

    <key>scope</key>
    <string>text.html</string>
    

    <key>scope</key>
    <string>text.html - comment</string>
    

    |--&gt;
    

    (?#|--&gt;)
    

    (这评论了结束评论正则表达式)

  7. 保存

但是,当 ST3 的下一个版本可用时,最好删除您的覆盖,以防它被正确修复。这样,您将继续获得这些文件的更新,否则您将被保存的版本卡住。去做这个:

  1. Preferences->Browse Packages
  2. 删除HTML文件夹
  3. 进入Default文件夹并删除Indentation Rules - Comments.tmPreferences文件

如果问题在下一个版本中没有得到解决,您可以简单地重新创建这些更改。

于 2016-07-08T07:47:54.030 回答
1

在 Sublime Text 3(构建 3103 和 3114)中尝试了您的示例,您是对的,当它找到注释块时缩进会中断。

显然,重新缩进功能总是很弱,HTML 并不是唯一不起作用的上下文(编辑:在 PHP 中也得到了确认,几乎相同的行为)。

如果尚未提交,我建议提交问题。

于 2016-07-07T18:26:36.793 回答