本文翻译自: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代码,使其看起来更好并且更易于阅读?


#1楼

参考:https://stackoom.com/question/b5cf/如何使用Sublime-Text-重新格式化HTML代码


#2楼

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


#3楼

There's a plugin called SublimeHtmlTidy which works pretty well 有一个名为SublimeHtmlTidy的插件,效果很好

https://github.com/welovewordpress/SublimeHtmlTidy https://github.com/welovewordpress/SublimeHtmlTidy


#4楼

Simply go to 只需转到

Edit -> Tag -> Auto-format tags on document 编辑->标签->自动格式化文档上的标签


#5楼

Just a general tip. 只是一般提示。 What I did to auto-tidy up my HTML, was install the package HTML_Tidy, and then add the following keybinding to the default settings (which I use): 我要做的是自动整理HTML,安装了软件包HTML_Tidy,然后将以下按键绑定添加到默认设置(我使用的是):

{ "keys": ["enter"], "command": "html_tidy" },

this runs HTML Tidy with every enter. 每次输入都会运行HTML Tidy。 There may be drawbacks to this, I'm quite new to Sublime myself, but it seems to do what I want :) 这可能有弊端,我对Sublime还是很陌生,但它似乎可以满足我的要求:)


#6楼

I am yet to have the privilege to comment so this is simply additional information related to @peter's answer above answer. 我还没有发表评论的特权,因此这仅仅是与@peter 答案上面的答案相关的其他信息。

I found HTML did not align as expected if IE conditional comments in the header were not completely in-line eg flush to the left: 我发现,如果标头中的IE 条件注释未完全内联(例如,向左刷新),则HTML不会按预期对齐:

<!--[if lt IE 7]>
<p class='chromeframe'>Your browser is <em>unsupported</em>. <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p>
<![endif]-->
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

如何使用Sublime Text 2重新格式化HTML代码?相关推荐

  1. (资源免费)Sublime Text 3如何格式化json文本+格式化Sql语句

    Sublime Text 3如何格式化json文本+格式化Sql语句 下面由sublime教程栏目给大家介绍sublime text3格式化json,希望对需要的朋友有所帮助! 问题研讨 当前后端对接 ...

  2. sublime c语言如何编译,Sublime Text 3 实现C语言代码的编译和运行(示例讲解)

    Sublime Text 3是一款优秀的代码编辑软件.界面简洁,轻巧快速,很受大家的欢迎. 最近开始用他来编辑数据结构的代码,这就需要在新建编译系统. 具体方法如下: 首先: 接下来是关键的一步,将以 ...

  3. Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux,支持32与64位,支持各种流行编程语言的语法高亮、代码补全等...

    Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux,支持32与64位,支持各种流行编程语言的语法高亮.代码补全等-- 语法高亮.代码提示补全. ...

  4. sublime3编程c语言,Sublime Text 3 实现C语言代码的编译和运行(示例讲解)

    Sublime Text 3 实现C语言代码的编译和运行(示例讲解) 发布时间:2020-10-14 12:48:35 来源:脚本之家 阅读:107 作者:jingxian Sublime Text ...

  5. Sublime Text 2 - 性感无比的代码编辑器

    Address: http://www.iplaysoft.com/sublimetext.html Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/ ...

  6. Lua sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux

    sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux [  编程开发,  编辑输入 -  Windows,  Mac,  Linux // 20 ...

  7. 将Sublime Text 2配置为C#代码编辑器(附配置文件)

    有时候我们需要编写一些小的代码片段时,在Visual Studio中创建一个工程就显得有点杀鸡用牛刀的感觉了,所有说对于一个程序员来说一款轻巧的代码编辑器还是很有必要的.原来我用的主要的Notepad ...

  8. sublime安装codeformat实现格式化php代码

    第一步 ctrl+shift+p 呼出控制台 输入 install package 进入搜索插件 第二步 搜索插件 codeformatter 安装 第三步 待出现如下tab页面 即安装成功 第四步 ...

  9. sublime text 3 中的php代码语法检测

    sublime text 3 中存在一个php 代码语法检测的插件,如果在sublime中编写php代码出现了语法错误,可以在左侧出现红色的提示标志: 如图所示: 那么这样的效果在sublime编辑器 ...

最新文章

  1. 太形象!打工人入职前后的心理变化 | 每日趣闻
  2. 35岁前务必成功的12级跳(男女通用) 转
  3. 机器学习--近邻成分分析(NCA)算法 和 度量学习
  4. LeetCode算法题-Jewels and Stones(Java实现)
  5. LeetCode 787. K 站中转内最便宜的航班(Dijkstra最短路径 + 优先队列)
  6. STM32F407+CubeMX+Keil上移植RTX5实时系统
  7. Go 语言本身提供的包管理机制
  8. linux 文件句柄 sock,linux socket句柄
  9. ffmpeg转码保留时间戳
  10. ElasticJob3.0整合SpringBoot,ElasticJob-Lite【ElasticJob入门篇】
  11. SAS学习7(gpolt过程、gchart过程、图形输出、ods功能、假设检验,ttest过程,rank过程,秩和检验(非参数检验))
  12. 光模块有什么用?什么是SFP光模块?
  13. AVR单片机实现modbus通讯协议
  14. 麻雀虽小,五脏俱全:从一个小功能看软件开发过程[转]
  15. indiegogo众筹
  16. 【历史上的今天】3 月 14 日:微软发布 IE9;黑莓创始人出生;圆周率计算创造新纪录
  17. 计算机综合布线考试试题A,答案_网络综合布线期末考试A卷.doc
  18. C# DataRow转DataTable
  19. 二分答案——路标设置(洛谷 P3853)
  20. 通用计算机考试系统,通用考试评卷系统

热门文章

  1. android build系统
  2. 算法-------三角形最小路径和(Java版本)
  3. 算法----------最长上升子序列(Java 版本)
  4. Android-Binder进程间通讯机制-多图详解
  5. 64位十六进制转浮点数
  6. Flutter开发之PageView指示器(31)
  7. GitLab安装文档
  8. 微信开发:微信js_sdk 分享,前端部分(二)
  9. Codeforces Educational 38 C. Constructing Tests ( 数学公式推导+暴力)
  10. 如何解决普通用户使用sudo找不到命令