在Notepad ++中格式化代码

dar*_*ren 182 html code-formatting notepad++

在Notepad ++中是否有用于格式化代码的键盘快捷键?
我主要使用HTML,CSS和Python代码.

例如:

<title>{% block title %}    {% endblock %}</title>      
 <link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>
Run Code Online (Sandbox Code Playgroud)

至:

<head>
  <title>
    {% block title %}
    {% endblock %}
  </title>
  <link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>
Run Code Online (Sandbox Code Playgroud)


我记得Visual Studio使用Ctrl+ K+ D和NetBeans也有这个功能但是在Notepad ++中找不到它,如果它甚至可以做到的话.

gab*_*lin 125

TextFX - > HTML Tidy - > Tidy:Reindent XML

在执行此操作之前,请务必选择HTML代码.

  • 对于那些下载新Notepad ++的人.TextFX不再捆绑了.您需要转到`Plugins> Plugin Manager> Show Plugin Manager`并从那里下载TextFX.最重要的是,你可能会发现TextFX找不到`libTidy.dll`.为了解决这个问题,你可以这样做http://stackoverflow.com/questions/6985637/notepad-htmltidy-unable-to-find-libtidy-dll完成所有这些后你应该能够`TextFX - > HTML Tidy - > Tidy :Reindent XML`作为@gablin描述. (157认同)
  • `Tidy2`插件将完成这项工作,`插件>插件管理器>显示插件管理器`然后添加`Tidy2`. (4认同)
  • _Seems Notepad ++想让生活变得困难_.即使您有**版本6或更高版本**,您仍然需要下载**zip版本5.9**[这里](http://download.tuxfamily.org/notepadplus/5.9/npp.5.9.bin.zip ).然后从`unicode\plugins\Config`复制`tidy`文件夹并将其粘贴到`C:\ Program Files\Notepad ++\plugins\Config`文件夹中. (2认同)

Dmi*_*mov 76

有一个像UniversalIndentGUI这样的插件,它可以直接从插件管理器安装,并有可能重新使用最常用的编程语言.

  • +1这很棒!安装UniversalIndentGUI插件并按Ctrl + Alt + Shift + J进行格式化. (10认同)
  • 值得注意的是"插件管理器"本身就是一个插件,是吗?由于不熟悉Notepad ++,它花了大量的菜单搜索失败,然后谷歌搜索才明白这一点.如果从头开始,它的安装过程需要考虑到该解决方案的"简单性". (2认同)
  • 这不起作用... format / auto-indent命令在哪里?没用。在2017-05-29的这一天,不会自动缩进PHP或JS。任何人都可以解释出什么问题了,为什么自动缩进PHP和JS代码这一简单的业务在***中证明了这种令人难以忍受的痛苦? (2认同)

use*_*332 20

如果你去TextFX菜单然后去TextFX Edit,你会看到一个菜单项Reindent C++ Code.

这也将格式化C#代码.


Tha*_*ama 9

以下是 Notepad ++中可用快捷方式的列表.

如果您没有所需的功能,您可以定义自己的宏并将它们分配给自定义快捷方式(我不习惯使用宏).

更新:我会在这里发布快捷方式,以防链接失效:

Shortcut    Command

Ctrl-C  Copy
Ctrl-X  Cut
Ctrl-V  Paste
Ctrl-Z  Undo
Ctrl-Y  Redo
Ctrl-A  Select All
Ctrl-F  Launch Find Dialog
Ctrl-H  Launch Find / Replace Dialog
Ctrl-D  Duplicate Current Line
Ctrl-L  Delete Current Line
Ctrl-T  Switch the current line position with the previous line position
F3  Find Next
Shft-F3 Find Previous
Ctrl-Shft-F Find in Files
Ctrl-F3 Find (volatil) Next
Ctrl-Shft-F3    Find (volatil) Previous
Ctrl-Shft-I Incremental Search
Ctrl-S  Save File
Ctrl-Alt-S  Save As
Ctrl-Shft-S Save All
Ctrl-O  Open File
Ctrl-N  New File
Ctrl-F2 Toggle Bookmark
F2  Go To Next Bookmark 
Shft-F2 Go To Previous Bookmark
Ctrl-G  Launch GoToLine Dialog
Ctrl-W  Close Current Document
Alt-Shft-Arrow keys or Alt + Left mouse click   Column Mode Select
F5  Launch Run Dialog
Ctrl-Space  Launch CallTip ListBox
Alt-Space   Launch Word Completion ListBox
Tab (selection of several lines)    Insert Tabulation or Space (Indent)
Shft-Tab (selection of several lines)   Remove Tabulation or Space (outdent)
Ctrl-(Keypad-/Keypad+) or Ctrl + mouse wheel butto  Zoom in (+ or up) and Zoom out (- or down)
Ctrl-Keypad/    Restore the original size from zoom 
F11 Toggle Full Screen Mode
Ctrl-Tab    Next Document
Ctrl-Shft-Tab   Previous Document
Ctrl-Shft-Up    Move Current Line Up
Ctrl-Shft-Down  Move Current Line Down
Ctrl-Alt-F  Collapse the Current Level
Ctrl-Alt-Shft-F Uncollapse the Current Level
Alt-0   Fold All
Alt-(1~8)   Collapse the Level (1~8)
Alt-Shft-0  Unfold All
Alt-Shft-(1~8)  Uncollapse the Level (1~8)
Ctrl-BackSpace  Delete to start of word
Ctrl-Delete Delete to end of word
Ctrl-Shft-BackSpace Delete to start of line
Ctrl-Shft-Delete    Delete to end of line
Ctrl-U  Convert to lower case
Ctrl-Shft-U Convert to UPPER CASE
Ctrl-B  Go to matching brace
Ctrl-Shft-R Start to record /Stop recording the macro
Ctrl-Shft-P Play recorded macro
Ctrl-Q  Block comment/uncomment
Ctrl-Shft-Q Stream comment
Ctrl-Shft-T Copy current line to clipboard
Ctrl-P  Print
Alt-F4  Exit
Ctrl-I  Split Lines
Ctrl-J  Join Lines
Ctrl-Alt-R  Text Direction RTL
Ctrl-Alt-L  Text Direction LT
F1  About
Run Code Online (Sandbox Code Playgroud)

  • 哈哈这一切并没有问题的捷径?为何发布?-1 (34认同)
  • 我没有看到格式化代码的快捷方式选项.至于一个宏,我不知道我该如何去做.不管怎么说,还是要谢谢你. (23认同)

Gra*_*zer 9

截至 2019 年 6 月的答复

XML Tools从插件管理器安装插件(至少在 Notepad++ 7.7 中)

然后单击插件 -> XML 工具 -> 漂亮打印(仅 XML 带换行符)

那是为我做的。

  • 这是此页面上唯一对我有用的解决方案,而且效果完美! (4认同)

Jac*_*ter 8

最新的插件是tidy2,可以通过插件>插件管理器>显示插件管理器安装.

我建议编辑config 1并设置quote-marks:no,特别是如果你有使用引号的脚本.

此外,整理不止一次可能会导致第一次插入&符号,然后第二次更换&符号.您可能希望使用配置将其发送到您需要的位置.


use*_*723 6

这不是你想要的答案,但这是我遇到同样问题时遇到的解决方案.

我是一个非常认真的Notepad ++用户,所以不要采取错误的方式.我已经开始使用NetBeans 8除Notepad ++之外的网站开发,因为您可以将其设置为autoformat,保存所有语言,并且有大量配置选项可用于格式化,最简单的细节.您可以查看它,发现它是与notepad ++结合使用的有用工具.它也是开源的,完全免费的,并且有一堆插件和其他有用的东西,如果你也使用它自动编译Sass.它绝对不如NP ++那么快,因此对于小编辑来说并不是很好,但对于长编码会话来说它可能很好.


pan*_*rma 5

对于JavaScript格式化,我使用记事本++ JSMin插件。