Formatting code in Notepad++

585,885

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
Share:
585,885

Related videos on Youtube

darren
Author by

darren

Updated on October 26, 2021

Comments

  • darren
    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
      darren over 13 years
      I'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
      Philip Rego over 6 years
      This needs a modern answer. None of these answers work anymore.
    • Muhammad Musavi
      Muhammad Musavi over 5 years
      You 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
    darren over 13 years
    I 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
    Thariama over 13 years
    macros are described here: stackoverflow.com/questions/362444/…
  • darren
    darren over 13 years
    Hey 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
    darren over 13 years
    been 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
    gablin over 13 years
    @mongoose_za: Hm, strange that Notepad++ handles those tags differently. Oh well.
  • Varun
    Varun over 12 years
    NO TEXTFX coming in latest notepad++ and unable to install plugins as well pls help
  • darren
    darren over 12 years
    For 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 find libTidy.dll. To fix that you can do this stackoverflow.com/questions/6985637/… After all of that you should be able to TextFX -> HTML Tidy -> Tidy: Reindent XML as @gablin described.
  • Admin
    Admin over 12 years
    Please 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
    darren almost 12 years
    Seems 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 from unicode\plugins\Config and paste it into your C:\Program Files\Notepad++\plugins\Config folder.
  • Anthony Walsh
    Anthony Walsh over 11 years
    In 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
    T_D almost 11 years
    +1 This works great! Install the UniversalIndentGUI plugin and press Ctrl+Alt+Shift+J to format.
  • obesechicken13
    obesechicken13 almost 11 years
    Thanks 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
    URL87 about 10 years
    How could I prevent it to make to tag in upper case ?
  • Jo Smo
    Jo Smo almost 10 years
    It 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
    Admin over 9 years
    The Tidy2 plugin will do the job, Plugins > Plugin Manager > Show Plugin Manager then add Tidy2.
  • Stabledog
    Stabledog over 9 years
    It 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
    ThomasG over 9 years
    though a plugin, it comes preinstalled in default Notepad++ installers
  • Stabledog
    Stabledog over 9 years
    It 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
    M H over 8 years
    Haha all that and no shortcut for the question? Why post it? -1
  • nikodaemus
    nikodaemus over 8 years
    Definitely not an answer to this question
  • W.M.
    W.M. about 8 years
    Is it possible to auto format PHP inside Netbeans? Do I need some additional plugin to do that? Thanks.
  • user3413723
    user3413723 about 8 years
    Yes 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
    Grischa over 7 years
    @George How is it possible to use Tidy2 for Notepad++ v6 64bit for windows?
  • mike rodent
    mike rodent almost 7 years
    I don't have a TextFX menu... what are you on about?
  • mike rodent
    mike rodent almost 7 years
    this 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
    user890332 almost 7 years
    You will need to install it through the plugins manager. It's called TextFX Characters.
  • Payedimaunt
    Payedimaunt almost 5 years
    Wrong answer, into the embedded plugin manager of Notepad++ can install and activate the functionality. IDE are not required.
  • Philip Rego
    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
    Shashi Shiva L over 4 years
    I installed latest notepad++ but the short cut is not working for me. Can you provide another answer please.
  • Shashi Shiva L
    Shashi Shiva L over 4 years
    @Payedimaunt , please provide the answer in detail.
  • Admin
    Admin over 4 years
    In 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
    Don Kelley over 4 years
    This is the ONLY solution on this page that worked for me, and it works perfectly!
  • GrumpyCrouton
    GrumpyCrouton almost 4 years
    This is a shortcut added by XML Tools.
  • WesternGun
    WesternGun over 3 years
    I downloaded JSTool plugin for JSON lint. Good.
  • ashokchhetri
    ashokchhetri over 2 years
    It 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
    zer00ne over 2 years
    It indents empty closed tags correctly, but not void tags, or closed tags with content. <closed></closed> 👍, <void> & <closed>text, CSS, or JavaScript</closed> 👎