如何在记事本中自动设置格式/缩进 XML/HTML++
有没有办法重新缩进代码块?我正在寻找类似于 Eclipse 中的 Ctrl+Shift+F 的东西(自动格式/缩进)。
需要明确的是,
- 我已经知道如何在 Notepad++ 之外格式化 XML(如上所述,Eclipse 工作得很好),因此我不需要一堆指向其他 XML 格式化工具的链接。
- 我专门从事 XML 和 HTML 工作。
- 理想情况下,有一个与 Eclipse 中的键绑定一样方便的键绑定,这样我就不必中断我的工作流程。
我已经了解 NppAutoIndent - 它不起作用,因为我正在使用 XML、HTML 和 CSS。
Is there a way to re-indent a block of code? I'm looking for something similar to Ctrl+Shift+F in Eclipse (Auto-Format/Indent).
To be clear,
- I already know how to format XML outside of Notepad++ (Eclipse works fine, as mentioned) so I don't need a bunch of links to other XML-formatting tools.
- I'm specifically working with XML and HTML.
- Ideally, there's a keybinding as convenient as the one in Eclipse, so I don't have to break my workflow.
I already know about NppAutoIndent - it won't work, as I'm working with XML, HTML and CSS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
自从升级到 6.3.2 以来,我使用
XML Tools
。菜单 → 插件 → XML 工具 → 漂亮打印)
在旧版本中:
菜单 → TextFX → HTML Tidy → Tidy:重新缩进 XML。
Since I upgraded to 6.3.2, I use
XML Tools
.menu → Plugins → XML Tools → Pretty Print)
In older versions:
menu → TextFX → HTML Tidy → Tidy: Reindent XML.
安装 Tidy2 插件。我有 Notepad++ v6.2.2,Tidy2 到目前为止工作正常。
Install Tidy2 plugin. I have Notepad++ v6.2.2, and Tidy2 works fine so far.
对于那些不知道的人来说,npp 有很多来自插件和其他项目的支持。您可以从 SourceForge 下载这些插件。
您需要
XML Tools
来格式化 n++ 中的文本。 下载
XML Tools
后 ..退出 Notepad++
转到
C:\Program文件\Notepad++
....你的N++ 安装文件夹。复制替换
将您下载的 xml 工具中的以下文件放置在 npp 根文件夹中< img src="https://i.sstatic.net/svpII.png" alt="在此处输入图像描述">
..\Plugins
子文件夹并将下载的文件放在下面<一href="https://i.sstatic.net/EmbRE.png" rel="noreferrer">
重新启动并享受吧!
Ctrl + Alt + Shft + B 进行格式化。
For those who don't know, npp has a lot of support from plugins and other projects. You can download those plugins from SourceForge.
You need
XML Tools
to format your text in n++After you have downloaded
XML Tools
..Exit Notepad++
Go To
C:\Program File\Notepad++
.... Your N++ installed folder.copy replace
..\Plugins
subfolder and place below downloaded fileRestart and enjoy!!!
Ctrl + Alt + Shft + B to format.
这是我第三次安装 Windows 和 npp,一段时间后我发现 tidy 功能不再起作用。所以我在谷歌上寻找解决方案,来到这个线程,然后在更多线程的帮助下我终于修复了它。我将一劳永逸地总结我所有的行动。
安装TextFX插件:Plugins ->插件管理器->显示插件管理器。选择 TextFX 字符并安装。重新启动 npp 后,菜单“TextFX”应该可见。 (来源:@remipod)。
通过粘贴旧 npp 包中的 Config 文件夹来安装 libtidy.dll:按照 这个答案。
在最新的 npp 安装目标(通常为 C:\Program Files (x86)\Notepad++\plugins)中拥有 Config 文件夹后,npp 需要对该文件夹的写入权限。右键单击Config文件夹->属性->安全选项卡 ->选择用户,点击编辑->选中完全控制以允许读/写访问。请注意,您需要管理员权限才能执行此操作。
重新启动 npp 并验证 TextFX -> TextFX HTML 整洁 -> Tidy:Reindent XML 有效。
It's been the third time that I install Windows and npp and after some time I realize the tidy function no longer work. So I google for a solution, come to this thread, then with the help of few more so threads I finally fix it. I'll put a summary of all my actions once and for all.
Install TextFX plugin: Plugins -> Plugin Manager -> Show Plugin Manager. Select TextFX Characters and install. After a restart of npp, the menu 'TextFX' should be visible. (credits: @remipod).
Install libtidy.dll by pasting the Config folder from an old npp package: Follow instructions in this answer.
After having a Config folder in your latest npp installation destination (typically C:\Program Files (x86)\Notepad++\plugins), npp needs write access to that folder. Right click Config folder -> Properties -> Security tab -> select Users, click Edit -> check Full control to allow read/write access. Note that you need administrator privileges to do that.
Restart npp and verify TextFX -> TextFX HTML Tidy -> Tidy: Reindent XML works.
不完全是一个解决方案,而是一个解决方法。
Notepad++ 默认不提供任何此类功能。但是您可以使用一些在线工具来自动设置文本格式,例如 https://www.freeformatter.com/xml -formatter.html。
Not exactly a solution but a workaround.
Notepad ++ doesn't provide any such feature by default. But you can use some online tools to autoformat text like https://www.freeformatter.com/xml-formatter.html.
只需安装最新的notepad++并安装indent By Fold即可。在菜单栏上选择插件 ->插件管理并选择缩进按折叠和安装。效果最好
Just install the latest notepad++ and install indent By fold. On the menu bar select Plugins -> Plugins Admin and selct indent By fold and the install. Works finest
我必须在插件 -> 下更新代理设置插件管理器->显示插件管理器 ->设置以查看“可用”列表中的任何插件。
之后,安装“XML Tools”就很容易了,并且完成了如上所述的要求的工作。
I had to update the proxy settings under Plugins -> Plugin Manager -> Show Plugin Manager -> Settings to see any PlugIns in the "Available" list.
After that, installing "XML Tools" was easy and did the requested job as described above.
要直接回答OP,请查看此人的网站: Thomas Hunter Notepad++ Tidy for XML。只需遵循简单的步骤,您就可以在 NPP 中获得非常漂亮的 XML 格式。到目前为止,我发现的唯一异常是嵌套自闭合元素 EG:
将整理为:
可能有一种方法可以解决此问题,但目前,它设法减少了我的文档中的行数300k 和这个特殊的异常是可以解决的。
To directly answer the OP, take a look at this guy's site: Thomas Hunter Notepad++ Tidy for XML. Simple steps to follow and you get very nice formatting of your XML right inside NPP. So far the only anomaly I've found is with nested self closing elements EG:
Will be tidied up to:
There may be a way to fix this, but for the time being, it's managed to reduce the number of lines in my document by 300k and this particular anomaly can be worked around.
我正在使用记事本 7.6 和“Plugin Admin”,但找不到 XML 工具。
我必须像 @some-java-guy 在他的 answer 中那样手动安装它,除了我的插件文件夹位于此处:
C:\Users\<我的用户名>\AppData\Local\Notepad++\plugins
在该目录中,我创建了一个新目录(名为 XmlTools)并将 XMLTools.dll 复制到其中。 (我将所有依赖项复制到 Program files 中的 Notepad++ 目录中。)
I'm using Notepad 7.6 with "Plugin Admin" and I could not find XML Tools.
I had to install it manually like @some-java-guy did in his answer except that my plugins folder was located here:
C:\Users\<my username>\AppData\Local\Notepad++\plugins
In that directory I created a new directory (named XmlTools) and copied XMLTools.dll there. (And I copied all dependencies to the Notepad++ directory in Program files.)