Html 在 Notepad++ 中格式化代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3635460/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:22:11  来源:igfitidea点击:

Formatting code in Notepad++

htmlnotepad++code-formatting

提问by darren

Is there a keyboard shortcut to format code in Notepad++ ?
I'm mainly working with HTML, CSS and Python code.

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

For example:

例如:

<title>{% block title %}    {% endblock %}</title>      
 <link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>

To:

到:

<head>
  <title>
    {% block title %}
    {% endblock %}
  </title>
  <link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>


I remember Visual Studio doing it with Ctrl+K+Dand NetBeans having the feature too but can't find it within Notepad++, if it can even do it.


我记得Visual Studio中做它Ctrl+ K+D和NetBeans具有的功能太多,但内记事本++无法找到它,如果它甚至可以做到这一点。

采纳答案by gablin

TextFX -> HTML Tidy -> Tidy: Reindent XML

TextFX -> HTML Tidy -> Tidy: Reindent XML

Remember to have the HTML code selected before you do this.

请记住在执行此操作之前选择 HTML 代码。

回答by Dmitry Avtonomov

there is such a pluginas UniversalIndentGUI, it can be installed right from the plugin managerand has possibilities to reindent the most used programming languages.

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

回答by user890332

If you go to TextFXmenu and go to TextFX Edit, you will see a menu item Reindent C++ Code.

如果您转到TextFX菜单并转到TextFX Edit,您将看到一个菜单项Reindent C++ Code

That will also format C# code.

这也将格式化 C# 代码。

回答by Thariama

Here is a listof the available shortcuts in Notepad++.

这是Notepad++ 中可用快捷方式的列表

In case your desired functionality is not available, you are able to define own macros and assign them to a custom shortcut (i am not used to use macros).

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

UPDATE: I will post the shortcuts here in case the link gets invalid:

更新:如果链接无效,我将在此处发布快捷方式:

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

回答by HymanArbiter

The latest plugin is tidy2, which can be installed through Plugins>Plugin Manager>Show Plugin Manager.

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

I suggest editing config 1 and setting quote-marks: no, especially if you have script that makes use of quotes.

我建议编辑配置 1 并设置引号:不,特别是如果您有使用引号的脚本。

Also, tidying more than once can result in inserting ampersands the first time and then replacing the ampersands the second time. You may want to play with the config to get it to where you need it.

此外,多次整理可能会导致第一次插入 & 号,然后第二次替换 & 号。您可能想要使用配置以将其带到您需要的地方。

回答by user3413723

This isn't quite the answer you were looking for, but it's the solution I came to when I had the same question.

这不是您正在寻找的答案,但这是我遇到相同问题时想到的解决方案。

I'm a pretty serious Notepad++ user, so don't take this the wrong way. I have started using NetBeans 8to develop websites in addition to Notepad++ because you can set it to autoformat on save for all your languages, and there are a ton of configuration options for how the formatting looks, down to the most minute detail. You might look into it and find it is a worthy tool to use in conjunction with notepad++. It's also open source, completely free, and has a bunch of plugins and other useful things like automatically compiling Sass if you use that too. It's definitely not as quick as NP++ so it's not great for small edits, but it can be nice for a long coding session.

我是一个非常认真的 Notepad++ 用户,所以不要误会。NetBeans 8除了 Notepad++ 之外,我还开始使用它来开发网站,因为您可以将其设置为在保存所有语言时自动格式化,并且有大量配置选项可用于格式化外观,甚至最细微的细节。您可能会研究它并发现它是一个值得与 notepad++ 结合使用的工具。它也是开源的,完全免费的,并且有一堆插件和其他有用的东西,比如自动编译 Sass,如果你也使用它的话。它绝对不如 NP++ 快,因此它不适用于小型编辑,但对于长时间的编码会话来说可能很好。

回答by panky sharma

For JavaScriptFormatting I use Notepad ++ JSMin Plugin.Quite Handy

对于 JavaScript格式,我使用 Notepad ++ JSMin Plugin。非常方便

回答by Grandizer

ANSWER AS OF June 2019

截至 2019 年 6 月的答复

Install the XML Toolsplugin from the Plugin Admin (in Notepad++ 7.7 at least)

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

Then click Plugins -> XML Tools -> Pretty Print (XML Only with Line breaks)

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

That did it for me.

那是为我做的。

回答by danny

In my notepad++, it seems TextFX needs a perl environment to format HTML files. Tidy2 demands nothing so I think it's more handy.

在我的记事本++中,TextFX 似乎需要一个 perl 环境来格式化 HTML 文件。Tidy2 不需要任何东西,所以我认为它更方便。

回答by wildwildwilliam

If all you need is alignment, try the plugin called Code Alignment.

如果您只需要对齐,请尝试使用名为 Code Alignment 的插件。

You can get it from the built-in plugin manager in Notepad++.

您可以从 Notepad++ 的内置插件管理器中获取它。