Formatting code in Notepad++

HtmlNotepad++Code Formatting

Html Problem Overview


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

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+D and NetBeans having the feature too but can't find it within Notepad++, if it can even do it.

Html Solutions


Solution 1 - Html

TextFX -> HTML Tidy -> Tidy: Reindent XML

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

Solution 2 - Html

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

Solution 3 - Html

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

That will also format C# code.

Solution 4 - Html

ANSWER AS OF June 2019

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

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

That did it for me.

Solution 5 - Html

Here is a list of the available shortcuts in 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

Solution 6 - Html

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

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

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.

Solution 7 - Html

For JavaScript Formatting I use Notepad ++ JSMin Plugin.Quite Handy

Solution 8 - Html

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

[update - I'm using vscode now for everything. I think it works better in a lot of cases.]

I'm a pretty serious Notepad++ user, so don't take this the wrong way. I have started using NetBeans 8 to 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.

Solution 9 - Html

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

Solution 10 - Html

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

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

Solution 11 - Html

We can use the following shortcut in the latest version of notepad++ for formatting the code

Alt + Ctrl + Shift + B

Solution 12 - Html

No. Notepad++ can't format by itself. Formatting can easily be accomplished in many IDEs like Eclipse, NetBeans, Visual Studio [Code].

Solution 13 - Html

In Plugins > Plugin Admin > Search 'XML Tools' > Install.

The window will restart and install XML Tools under plugins.

Open your file and click Ctrl + Alt + Shift + B

Solution 14 - Html

NPP+ v7.9.1 with the latest version of XMLTools can't format exported VBA code from Office 2016/2019 Word. It puts all the code on the same line since it strips the CRLF out. Moreover, when you enable "auto validation" it errors out on the first VBA line that is, Attribute VB_Name = "The VBA module name". So any of the xml tool validations apparently can't be used for VBA validation.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondarrenView Question on Stackoverflow
Solution 1 - HtmlgablinView Answer on Stackoverflow
Solution 2 - HtmlDmitry AvtonomovView Answer on Stackoverflow
Solution 3 - Htmluser890332View Answer on Stackoverflow
Solution 4 - HtmlGrandizerView Answer on Stackoverflow
Solution 5 - HtmlThariamaView Answer on Stackoverflow
Solution 6 - HtmlJackArbiterView Answer on Stackoverflow
Solution 7 - Htmlpanky sharmaView Answer on Stackoverflow
Solution 8 - Htmluser3413723View Answer on Stackoverflow
Solution 9 - HtmldannyView Answer on Stackoverflow
Solution 10 - HtmlwildwildwilliamView Answer on Stackoverflow
Solution 11 - HtmlitzmebibinView Answer on Stackoverflow
Solution 12 - HtmlPhilip RegoView Answer on Stackoverflow
Solution 13 - HtmlNevetsKuroView Answer on Stackoverflow
Solution 14 - HtmlM SWView Answer on Stackoverflow