【问题标题】:Indentation Error with Sublime TextSublime 文本的缩进错误
【发布时间】:2016-11-09 22:08:55
【问题描述】:

我正在尝试使用 Sublime Text 3 for HTML 中的自动缩进功能。我在 html 中有一些块 cmets,然后选择 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>

有什么想法吗?

【问题讨论】:

  • 不加评论能用吗?
  • 是的,它在没有注释块的情况下重新缩进时缩进很好。
  • 可以确认,ST3 3103 发生在我身上的确切问题

标签: html sublimetext3 indentation auto-indent text-indent


【解决方案1】:

我已在此处记录问题:https://github.com/SublimeTextIssues/Core/issues/1271

这种行为的原因是因为 Sublime Text 默认设置为保留 cmets 的缩进。要禁用此功能:

  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. &lt;key&gt;preserveIndent&lt;/key&gt;下的&lt;true/&gt;改为&lt;false/&gt;
  9. 保存文件

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


我还建议编辑 HTML 缩进规则以忽略 cmets,这样它就不会根据 cmets 中的标签更改缩进。即否则

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

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

  7. 保存

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

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

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

【讨论】:

  • 太棒了。很好的答案。我按照步骤操作,一切都按预期进行。我很欣赏详细程度。我会留意未来的更新。
  • 这个软件包还可以帮助“修复”缩进损坏的文件:packagecontrol.io/packages/Normalize%20Indentation
【解决方案2】:

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

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

如果尚未提交,我会推荐 submitting the issue

【讨论】:

猜你喜欢
  • 2013-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-19
  • 1970-01-01
  • 2020-06-26
  • 2014-09-28
  • 2020-06-25
相关资源
最近更新 更多