如何在 Notepad ++ 编辑器中缩进 HTML 或 PHP 代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14678080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I indent HTML or PHP code in Notepad ++ editor?
提问by JBa
How can I indent HTML or PHP code in notepad ++ editor to organize my code better?
如何在记事本 ++ 编辑器中缩进 HTML 或 PHP 代码以更好地组织我的代码?
采纳答案by Oleg Vaskevich
If you want auto-formatting, look at SourceFormatX, which is a paid plug-in for Notepad++.
如果您想要自动格式化,请查看SourceFormatX,它是 Notepad++ 的付费插件。
Other than that, there are a few free plug-ins available on the Notepad++ Wikiwhich will format either HTML or PHP code.
除此之外,Notepad++ Wiki上还有一些免费插件可用,它们可以格式化 HTML 或 PHP 代码。
回答by Niet the Dark Absol
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.
通常的做法是为每个当前打开的“块”缩进一个级别。在 PHP 中,“块”只是{和之间的代码}。在 HTML 中,“块”是任何未在同一行上关闭的标记。
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.
在 Notepad++(和许多其他代码编辑器)中,您可以选择多行代码并按 Tab 缩进整个选择(或 Shift+Tab 使其缩进)。这应该有助于保持代码整洁。
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.
另一件需要注意的事情是 Notepad++ 可以为您折叠块。在行号旁边,您应该会看到一棵带[-]框的树。您可以单击它们以折叠它们正在标记的块,从而更好地了解代码。
回答by netadictos
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:
如果您需要一个插件来格式化您的 HTML,不清楚您是否只想使用 Tab,但按照常识,我想您正在寻找一种软件来重新缩进代码。有一个插件 Tidy2 在:
https://github.com/davegb3/NppTidy2
https://github.com/davegb3/NppTidy2
With this you can reformat all your HTML code, and change how to do it, which is often interesting.
有了它,您可以重新格式化所有 HTML 代码,并更改如何执行此操作,这通常很有趣。
回答by netadictos
Select part of your code or any text and then press tab, it will indent all selected lines. Press shift + tabfor unindent.
选择部分代码或任何文本,然后按tab,它将缩进所有选定的行。按shift + tab取消缩进。

