Home computickets How to set up code auto-formatting in Sublime 3

How to set up code auto-formatting in Sublime 3

Author

Date

Category

How do I set up code auto-formatting in Sublime 3?

Let’s say I pasted HTML code into Sublime Text. This code with the same tabulation, respectively, turns out to be a mess.

How to make the code format itself and take its normal form after a certain action?

& lt; form & gt;
       & lt; div & gt;
    & lt; div & gt; & lt; / div & gt;
    & lt; div & gt;
      & lt; div & gt;
       & lt; img & gt;
     & lt; / div & gt;
     & lt; div & gt;
      & lt; input & gt;
    & lt; / div & gt;
  & lt; / div & gt;
& lt; / div & gt;
& lt; / form & gt;

Answer 1, authority 100%

By standard means

Preferences Key Bindings - User

If the file is empty, then insert the entire code.
If not, then add the object to the array as you would add it to JSON.

[
  {"keys": ["ctrl + alt + l"], "command": "reindent", "args": {"single_line": false}}
]

This code allows, by pressing the combination CTRL + ALT + L , to format the code in the whole file or only inside the selection.


Using a third party plugin

There is a plugin Sublime-HTMLPrettify . It needs node.js installed to work.
Can read settings from .jsbeautifyrc file.

Installation :

  • Press CTRL + SHIFT + P or CMD + SHIFT + < kbd>P on Linux / Windows / OS X
  • Type install , select Package Control: Install Package
  • Type prettify , select HTML-CSS-JS Prettify

Usage (any of the options)

  • Select Tools Command Palette (CTRL + SHIFT + P or CMD + SHIFT + P ) and type htmlprettify .
  • Press CTRL + SHIFT + H (or CMD + SHIFT + H if you have a Mac).
  • Right click on the selection HTML / CSS / JS Prettify Prettify Code
  • Open your HTML, CSS or JavaScript file, open the Sublime Text console via View Show Console and type view.run_command ("htmlprettify") .

An example of working on your code snippet:

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions