Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

html - 如何使用Sublime Text 2重新格式化HTML代码?(How do I reformat HTML code using Sublime Text 2?)

I've got some poorly-formatted HTML code that I'd like to reformat.

(我有一些格式很差的HTML代码,我想重新格式化。)

Is there a command that will automatically reformat HTML code in Sublime Text 2 so it looks better and is easier to read?

(是否有一个命令可以自动在Sublime Text 2中重新格式化HTML代码,使其看起来更好并且更易于阅读?)

  ask by Ravi Ram translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need any plugins to do this.

(您不需要任何插件即可执行此操作。)

Just select all lines ( Ctrl A ) and then from the menu select Edit → Line → Reindent.

(只需选择所有行( Ctrl A ),然后从菜单中选择“编辑”→“行”→“重新缩进”。)

This will work if your file is saved with an extension that contains HTML like .html or .php .

(如果您使用扩展名包含HTML的扩展名(如.html.php来保存文件,则此方法有效。)

If you do this often, you may find this key mapping useful:

(如果您经常这样做,则可能会发现此键映射很有用:)

{ "keys": ["ctrl+shift+r"], "command": "reindent" , "args": { "single_line": false } }

If your file is not saved (eg you just pasted in a snippet to a new window), you can manually set the language for indentation by selecting the menu View → Syntax → language of choice before selecting the reindent option.

(如果未保存文件(例如,您只是将其粘贴到新窗口中),则可以在选择“重新缩进”选项之前通过选择菜单“视图”→“语法”→ language of choice的语言”来手动设置缩进的language of choice 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...