How can I indent HTML or PHP code in notepad ++ editor to organize my code better?
Now you can use shortcut key CTRL+ALT+SHIFT+B to indent the 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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With