How do I reformat HTML code using Sublime Text 2?

 

In Sublime Text 2, you can reformat HTML code using the built-in "Reindent" functionality. Here's how you can do it with an example:

  1. Open Sublime Text 2.

  2. Paste or open your HTML code in a new or existing file.

  3. Select the HTML code that you want to reformat.

  4. To reformat the selected code, go to the "Edit" menu, then select "Line" and finally "Reindent" from the submenu.

    Alternatively, you can use the keyboard shortcut: Ctrl + ] (Windows/Linux) or Cmd + ] (Mac).

Here's an example:

Before reformatting:

html
<!DOCTYPE html><html><head><title>My Page</title></head><body><h1>Hello</h1><p>This is a paragraph</p></body></html>

After reformatting:

html
<!DOCTYPE html> <html> <head> <title>My Page</title> </head> <body> <h1>Hello</h1> <p>This is a paragraph</p> </body> </html>

Sublime Text 2 will automatically adjust the indentation of your HTML code to make it more readable and consistent.

Keep in mind that Sublime Text 2 is an older version of the Sublime Text editor. The steps mentioned above should still be applicable to Sublime Text 2, but I recommend considering upgrading to a newer version for the latest features and improvements.

Comments