How can I indent HTML or PHP code in notepad ++ editor to organize my code better?
-
You can indent by adding spaces or tabs. Is this a programming question?Nightfirecat– Nightfirecat2013-02-03 22:52:04 +00:00Commented Feb 3, 2013 at 22:52
-
2If you like to see some standards regarding indenting and format your PHP code, have a look at the PSR-1/2 code styles: github.com/php-fig/fig-standards/blob/master/accepted/… and github.com/php-fig/fig-standards/blob/master/accepted/…thaJeztah– thaJeztah2013-02-04 00:02:48 +00:00Commented Feb 4, 2013 at 0:02
4 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.
1 Comment
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.
Comments
If you need a plugin to format your HTML, it is not clear if you only want to tab, but in common sense, I suppose you're looking for a software to reindent the code. There is a plugin Tidy2 in:
https://github.com/davegb3/NppTidy2
With this you can reformat all your HTML code, and change how to do it, which is often interesting.