Formatting code in Notepad++
Solution 1
TextFX -> HTML Tidy -> Tidy: Reindent XML
Remember to have the HTML code selected before you do this.
Solution 2
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
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
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
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
Related videos on Youtube
darren
Updated on October 26, 2021Comments
-
darren over 2 years
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.-
darren over 13 yearsI've been using Dreamweaver "Apply Source Formatting" or CRTL + K + D in Visual Studio and format my pages. I've also used VIM but I just never got it right with Notepadd++ because it doesn't like my django tags.
-
Philip Rego over 6 yearsThis needs a modern answer. None of these answers work anymore.
-
Muhammad Musavi over 5 yearsYou need to add related plugin which is accessible through
Plugin manger
, the point is as of Notepad++ version 7.5, plugin manager is no longer shipped with Notepad++
-
-
darren over 13 yearsI don't see a shortcut option there that formats code. As for a macro I have no idea how I'd go about that. Thanks anyway.
-
Thariama over 13 yearsmacros are described here: stackoverflow.com/questions/362444/…
-
darren over 13 yearsHey there, I used that and it works nicely with only HTML. With django tags however seems to just erase them or not format them properly. It's the closest so far. Ta for the tip.
-
darren over 13 yearsbeen trying out your suggested method for a while now and it's close but still not quite what I need. I guess the Django tags are what really seem to through the formatter out.
-
gablin over 13 years@mongoose_za: Hm, strange that Notepad++ handles those tags differently. Oh well.
-
Varun over 12 yearsNO TEXTFX coming in latest notepad++ and unable to install plugins as well pls help
-
darren over 12 yearsFor those who download the new Notepad++. TextFX is not bundled anymore. You'll need to go to
Plugins > Plugin Manager > Show Plugin Manager
and download TextFX from there. On top of that you'll probably find that TextFX can't findlibTidy.dll
. To fix that you can do this stackoverflow.com/questions/6985637/… After all of that you should be able toTextFX -> HTML Tidy -> Tidy: Reindent XML
as @gablin described. -
Admin over 12 yearsPlease note that you can no longer get the TextFX plugin with the Unicode executable of Notepad++. You have to download the ZIP, and use the ANSI version to get TextFX.
-
darren almost 12 yearsSeems Notepad++ want to make life difficult. EVEN if you have version 6 or higher you still need to download the zip version 5.9 here. Then copy the
tidy
folder fromunicode\plugins\Config
and paste it into yourC:\Program Files\Notepad++\plugins\Config
folder. -
Anthony Walsh over 11 yearsIn my case there were no plugins listed under the 'Available' tab of the 'Plugin Manager'. To fix it I had to amend firewall rules for Notepad++ and the 'Plugin Manager' then displayed the full list of downloadable plugins as expected.
-
T_D almost 11 years+1 This works great! Install the UniversalIndentGUI plugin and press Ctrl+Alt+Shift+J to format.
-
obesechicken13 almost 11 yearsThanks this works great. Is there a way to automatically format the code when you save? Right now, when I check enable autoupdate text, it doesn't update when I save or exit the file.
-
URL87 about 10 yearsHow could I prevent it to make to tag in upper case ?
-
Jo Smo almost 10 yearsIt doesn't indent correctly in PHP. Sometimes it makes 2 or 3 tab spaces instead of one, and in some situations it makes none, when it should.
-
Admin over 9 yearsThe
Tidy2
plugin will do the job,Plugins > Plugin Manager > Show Plugin Manager
then addTidy2
. -
Stabledog over 9 yearsIt seems worth noting that "the plugin manager" is itself a plug-in, yes? Being unfamiliar with Notepad++, it took a fair amount of failed menu searching followed by Googling to understand this. Its installation process needs to be factored into the "simplicity" of this solution if one is starting from scratch.
-
ThomasG over 9 yearsthough a plugin, it comes preinstalled in default Notepad++ installers
-
Stabledog over 9 yearsIt did not come preinstalled in my version, and I see that in Win7, one must do manual tweaks to get it to run: brotherstone.co.uk/npp/pm/#install I even had to create the plugins/ and updater/ directories as administrator, and it took quite a while to learn this.
-
M H over 8 yearsHaha all that and no shortcut for the question? Why post it? -1
-
nikodaemus over 8 yearsDefinitely not an answer to this question
-
W.M. about 8 yearsIs it possible to auto format PHP inside Netbeans? Do I need some additional plugin to do that? Thanks.
-
user3413723 about 8 yearsYes Netbeans autoformats PHP, but you probably need to make sure that you have the php version, or at least have the php plugin installed. On windows the key combo to autoformat is Alt+Shift+F.
-
Grischa over 7 years@George How is it possible to use
Tidy2
for Notepad++ v6 64bit for windows? -
mike rodent almost 7 yearsI don't have a TextFX menu... what are you on about?
-
mike rodent almost 7 yearsthis doesn't work... Where is the format/auto-indent command? Nothing works. Nothing will auto-indent either PHP or JS on this day 2017-05-29. Can anyone explain what's going wrong and why the simple business of automatically indenting PHP and JS code is proving such a b*tching pain in the ***?
-
user890332 almost 7 yearsYou will need to install it through the plugins manager. It's called TextFX Characters.
-
Payedimaunt almost 5 yearsWrong answer, into the embedded plugin manager of Notepad++ can install and activate the functionality. IDE are not required.
-
Philip Rego almost 5 years"by itself". Have fun trying to get Notepad++ to format when you don't have access to install plugins.
-
Shashi Shiva L over 4 yearsI installed latest notepad++ but the short cut is not working for me. Can you provide another answer please.
-
Shashi Shiva L over 4 years@Payedimaunt , please provide the answer in detail.
-
Admin over 4 yearsIn which version and on what content type is that shortcut supposed to work? Tried it in Notepad++ v7.7.1 with no effect.
-
Don Kelley over 4 yearsThis is the ONLY solution on this page that worked for me, and it works perfectly!
-
GrumpyCrouton almost 4 yearsThis is a shortcut added by XML Tools.
-
WesternGun over 3 yearsI downloaded
JSTool
plugin for JSON lint. Good. -
ashokchhetri over 2 yearsIt worked for me as well. But This is the Right Step After installing the XML Tools From the Plugins>Plugin Admin: Plugins -> XML Tools -> Pretty Print After installing the XML Tools From the Plugins>Plugin Admin. Try: Ctrl + Alt + Shift + B
-
zer00ne over 2 yearsIt indents empty closed tags correctly, but not void tags, or closed tags with content.
<closed></closed>
👍,<void>
&<closed>text, CSS, or JavaScript</closed>
👎