Menu
Sublime text mac版是一个代码编辑器.也是HTML和散文先进的文本编辑器。漂亮的用户界面和非凡的功能,例如迷你地图,多选择,Python的插件,代码段,等等。完全可自定义键绑定,菜单和工具栏。.
Active1 year, 9 months ago
I've got some poorly-formatted HTML code that I'd like to reformat. Is there a command that will automatically reformat HTML code in Sublime Text 2 so it looks better and is easier to read?
Ravi RamI mean having the ability to write a python script that utilizes a 3rd party module in Sublime Text, and then Build it within sublime text. – jackmac92 Sep 20 '14 at 20:38 Oh; that sounds like it should just work. 都说 sublime text 2 比较好,但下载回来发觉需要弄插件比较麻烦,百度的比较散而且针对mac的没有太多,html的头部文件需要怎样快速插入,怎样在浏览器浏览。.
Ravi Ram12.9k1818 gold badges6363 silver badges9090 bronze badges
15 Answers
You don't need any plugins to do this.Just select all lines (Ctrl A) and then from the menu select Edit → Line → Reindent.This will work if your file is saved with an extension that contains HTML like
.html
or .php
.If you do this often, you may find this key mapping useful:
If your file is not saved (e.g. you just pasted in a snippet to a new window), you can manually set the language for indentation by selecting the menu View → Syntax →
Patrick Mlanguage of choice
before selecting the reindent option.7,09688 gold badges4949 silver badges9090 bronze badges
peterpeter37k55 gold badges5050 silver badges8989 bronze badges
There are half a dozen or so ways to format HTML in Sublime. I've tested each of the most popular plugins (see the writeup I did on my blog for full details), but here's a quick overview of some of the most popular options:
Reindent command
Pros:
- Ships with Sublime, so no plugin install needed
Cons:
- Doesn't delete extra blank lines
- Can't handle minified HTML, lines with multiple open tags
- Doesn't properly format
<script>
blocks
Tag
Pros:
- Supports ST2/ST3
- Removes extra blank lines
- No binary dependencies
Cons:
- Chokes on PHP tags
- Doesn't handle
<script>
blocks correctly
HTMLTidy
Pros:
- Handles PHP tags
- Some settings to tweak formatting
Cons:
- Requires PHP (falls back to web service)
- ST2 only
- Abandoned?
HTMLBeautify
Pros:
- Supports ST2/ST3
- Simple and no binaray dependencies
- Support for OS X, Win and Linux
Cons:
- Chokes a bit with inline comments
- Does expand minimized/compressed code
HTML-CSS-JS Prettify
Pros:
- Supports ST2/ST3
- Handles HTML, CSS, JS
- Great integration with Sublime's menus
- Highly customizable
- Per-project settings
- Format on save option
Cons:
- Requires Node.js
- Not great for embedded PHP
Which is best?
HTML-CSS-JS Prettify is the winner in my book. Lots of great features, not much to complain about.
Josh EarlJosh Earl12.6k1414 gold badges5656 silver badges9090 bronze badges
The only package I've been able to find is Tag.
You can install it using the package control. https://sublime.wbond.net
After installing package control. Go to package control (Preferences ->Package Control) then type
install
, hit enter. Then type tag
and hit enter.After installing Tag, highlight the text and press the shortcut Ctrl+Alt+F.
tristansokol3,35411 gold badge88 silver badges2626 bronze badges
dardubdardub2,58933 gold badges2424 silver badges2929 bronze badges
I recommend this plugin: HTML/CSS/JS Prettify, It really works.
After the installation, just select the code and press Ctrl+Shift+H.
Apps to monitor text iphone. Done!
Ulf Gjerdingen1,29533 gold badges1414 silver badges2020 bronze badges
Peter ZhuPeter Zhu
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):
this runs HTML Tidy with every enter. There may be drawbacks to this, I'm quite new to Sublime myself, but it seems to do what I want :)
AnnekeAnneke
Altough the question is for HTML, I would also additionally like to give info about how to auto-format your Javascript code for Sublime Text 2;
You can select all your code(ctrl + A) and use the in-app functionality, reindent(
Edit
->Line
->Reindent
) or you can use JsFormat formatting plugin for Sublime Text 2
if you would like to have more customizable settings on how to format your code to addition to the Sublime Text's default tab/indent settings. You can easily install JsFormat with using Package Control (
Preferences
->Package Control
) Open package control then type install, hit enter. Then type js format
and hit enter, you're done. (The package controller will show the status of the installation with success and errors on the bottom left bar of Sublime
)Add the following line to your key bindings (
Preferences
->Key Bindings User
) I'm using ctrl + alt + 2, you can change this shortcut key whatever you want to. So far,
JsFormat
is a good plugin, worth to try it!Hope this will help someone.
Gokhan TankGokhan Tank3,46211 gold badge1616 silver badges1616 bronze badges
There's a plugin called SublimeHtmlTidy which works pretty well
Christian HagelidChristian Hagelid7,05544 gold badges3636 silver badges6161 bronze badges
For me, the
HTML Prettify
solution was extremely simple. I went to the HTML Prettify page. - Needed the
Sublime Package Manager
- Followed the Instructions for installing the package manager here
- typed cmd + shift + p to bring up the menu
- Typed
prettify
- Chose the
HTML prettify
selection in the menu
Boom. Done. Looks great
jezrael407k3232 gold badges425425 silver badges490490 bronze badges
insaineyesayinsaineyesay
Simply go to
Edit -> Tag -> Auto-format tags on document
Ricardo MartinsRicardo Martins3,87111 gold badge3030 silver badges4747 bronze badges
I created a Package called HTMLBeautify that does a decent job of reformatting HTML. I based it off of a Perl script I found back in 1997—I updated it to work with all the new fangled modern tags. :)
Check it out and let me know what you think!
RossRoss
I am yet to have the privilege to comment so this is simply additional information related to @peter's answer above answer.
I found HTML did not align as expected if IE conditional comments in the header were not completely in-line e.g. flush to the left:
Community♦
Mac Sublime Text
newtriksnewtriks
There is a nice open source CodeFormatter plugin, which(along reindenting) can beautify dirty code even all of it is in single line.
side2kside2k1,80933 gold badges1414 silver badges1313 bronze badges
I think this is what you're looking for:
Allen BargiAllen Bargi10.6k88 gold badges5151 silver badges5858 bronze badges
I'm using tidy together with custom build system to prettify HTML.
I have HTMLTidy.sublime-build in my Packages/User/ directory:
and tidy_config.cfg file in the same directory:
And just select build system and press ctrl+b or cmd+b to reformat file content. One minor issue with that is that ST2 does not automatically reload the file so to see the results you have to switch to some other file and back (or to other application and back).
On Mac I've used macports to install tidy, on Windows you'd have to download it yourself and specify working directory in the build system, where tidy is located:
or add it to the PATH.
rchlrchl
![Sublime text format html Sublime text format html](/uploads/1/2/6/0/126081909/767452427.jpg)
you can set shortcut key F12 easy!!!
see detail here.
Sumeta PongpannaSumeta Pongpanna
protected by Samuel Liew♦Oct 5 '15 at 9:20
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged htmlsublimetext2sublimetextindentationreformat or ask your own question.
Viewed 516 times
I've seen questions similar to this but haven't found a workable answer. I'm looking to learn more about Python coding, I've been coding a lot with Ruby, but would like to use Python for some 3rd Party modules which don't seem to have a Ruby equivalent. RVM and gems made 3rd party really easy to work with, is there an equivalent for Python? I've installed Python through Macports and Homebrew, and have tried to install 3rd party modules through Macports ('sudo port install') and pip. Although the modules seem to install successfully, I can't get any non-standard modules to run in Sublime Text.
On the Sublime Text side, I managed to get Python to build by creating a new build system based on suggestions from here
and also by using the Sublime-REPL package. I've also read that virtualenv is a common way to utilize 3rd party modules, as it will prevent conflicts.
Sublime Text 3 Download Mac
So my question is, How can I get Python to run in Sublime Text like Ruby did. How can I set up Sublime text so that it points to the correct directory where 3rd party modules are installed, so that it can build something that includes one of these modules. I'm guessing there are multiple ways to do this, I'm just looking for the most straightforward approach.
Sublime Text Editor For Mac
Any tips appreciated, thanks in advance
jackmac92jackmac92
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.