Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I indent HTML or PHP code in Notepad ++ editor?

How can I indent HTML or PHP code in notepad ++ editor to organize my code better?

like image 283
JBa Avatar asked Feb 03 '13 22:02

JBa


People also ask

How do I Indent HTML in notepad?

Now you can use shortcut key CTRL+ALT+SHIFT+B to indent the code.

How do I Indent PHP code?

Spacing and indentation should be consistent throughout your code. Many developers choose to use 4-space or 2-space indentation. In PHP, each nested statement (e.g., a statement following a "{" brace) should be indented exactly once more than the previous line's indentation.

How can I write PHP code in notepad?

In Notepad, add . php to the end of the filename and enclose in double quotations. This ensures the file will not be converted into a basic text file by Notepad.


2 Answers

If you want auto-formatting, look at SourceFormatX, which is a paid plug-in for Notepad++.

Other than that, there are a few free plug-ins available on the Notepad++ Wiki which will format either HTML or PHP code.

like image 68
Oleg Vaskevich Avatar answered Oct 04 '22 21:10

Oleg Vaskevich


It is generally common practice to indent one level for each currently open "block". In PHP, a "block" is simply code between { and }. In HTML, a "block" is any tag that is not closed on the same line.

In Notepad++ (and many other code editors) you can select several lines of code and hit Tab to indent the entire selection (or Shift+Tab to outdent it). This should help keep your code tidy.

Another thing to note is that Notepad++ can collapse blocks for you. Next to the line numbers, you should see a tree with [-] boxes. You can click those to collapse the block they're marking, allowing you to get a better overview of your code.

like image 44
Niet the Dark Absol Avatar answered Oct 04 '22 20:10

Niet the Dark Absol