本文介绍了Sublime Text不能用HTML正确缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

相关但不完全相同的问题:插件,以前称为Zen Coding。它允许你使用类似CSS选择器的语法输入HTML,例如

  html> body> div.main 

然后按下即可获得

 < html> 
< body>
< div class =main> |< / div>
< / body>
< / html>

其中 | 是光标位置。更重要的是,对于您现在的问题,只需输入 body 就可以获得

 <身体GT; 
|
< / body>

就像您正在寻找的一样。详细信息请参阅。


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

  1. Press tab after writing tag to autocomplete the closing tag.
  2. Press enter, which brings the closing tag one line.
  3. Press enter again, which brings the closing tag onto the third line.
  4. Press the up key to get to the second line.
  5. Press the tab key again, which I would expect to properly indent, but instead, it brings me to the end of the closing tag on the third line.
  6. Press the up key again to get to the second line again.
  7. Press the tab key again, which finally indents the line properly.
  8. Continue writing more HTML.

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?

解决方案

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

<body>
    |
</body>

just like you were looking for. See the Emmet docs for all the details.

这篇关于Sublime Text不能用HTML正确缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:16