6

Can Notepad++ correctly indent code?

If I had this:

<div><div><div></div></div>   </div>

Is there a way of turning it into the following?

<div>
  <div>
    <div>
    </div>
  </div>
</div>
  • This is asking about reindenting - if it was changing the behaviour when pressing Enter (auto indent), it would be the checkbox in menu SettingsPreferencesMISC.Auto Indent – Peter Mortensen Jul 20 '18 at 11:18
2

You can use TextFX plugin to reindent code for you. If you don't have it, you will need to install in from your plugin manager. Once in place > just use the menu "TextFX" > "TextFX Edit" > "Reindent C++ code".

Probably it won't convert a single line, but actual code with miss-indentations will be handled well.

You will find more info and other plugins explained here.

|improve this answer|||||
  • 3
    The OP asked about HTML, not about C++ – CodyBugstein Feb 9 '14 at 20:44
  • 1
    And just to be doubly clear: the "Reindent C++ code" action does not indent my HTML code (N++ v6.5.1) – Daryn Mar 27 '14 at 21:33
  • @Imray Really? You don't say. – Mariyan Mar 28 '14 at 7:53
  • @Daryn At the time of writing (1 year ago) this was working. – Mariyan Mar 28 '14 at 7:55
  • @Magnum I hear you. That's why I added version number, I know these things change over time. – Daryn Mar 28 '14 at 17:48
4

Install Indent by Fold plugin. It works well with XML (or, derivatives) tags.

|improve this answer|||||
  • Tried it...nothing happened. :( – Michael Yaeger May 27 '17 at 14:58
0

All of my code was on a single line (minified). What I did was use an online "unminifier" to bust up the code into multiple lines. There are many available if you search Google, but here's the one that worked best for me: http://mrcoles.com/blog/css-unminify/

I, then, used the plugin @Magnum mentioned (TextFX) to dress up the indents in the code further. The result was great!

Before:

object(stdClass)#2 (1) { ["GetDocTypeListResult"]=> object(stdClass)#3 (1) { ["DocType"]=> array(14) { [0]=> object(stdClass)#4 (2) { ["id"]=> string(3) "180" ["name"]=> string(49) "Return Merchandise Authorization and Notification" } [1]=> object(stdClass)#5 (2) { ["id"]=> string(3) "810" ["name"]=> string(16) "Customer Invoice" } [2]=> object(stdClass)#6 (2) { ["id"]=> string(3) "816" ["name"]=> string(28) "Organizational Relationships" } [3]=> object(stdClass)#7 (2) { ["id"]=> string(3) "820" ["name"]=> string(31) "Payment Order Remittance Advice" } [4]=> object(stdClass)#8 (2) { ["id"]=> string(3) "824" ["name"]=> string(18) "Application Advice" } [5]=> object(stdClass)#9 (2) { ["id"]=> string(3) "830" ["name"]=> string(41) "Planning Schedule with Release Capability" } [6]=> object(stdClass)#10 (2) { ["id"]=> string(3) "840" ["name"]=> string(21) "Request for Quotation" } [7]=> object(stdClass)#11 (2) { ["id"]=> string(3) "846" ["name"]=> string(24) "Inventory Inquiry/Advice" } [8]=> object(stdClass)#12 (2) { ["id"]=> string(3) "850" ["name"]=> string(14) "Purchase Order" } [9]=> object(stdClass)#13 (2) { ["id"]=> string(3) "852" ["name"]=> string(21) "Product Activity Data" } [10]=> object(stdClass)#14 (2) { ["id"]=> string(3) "860" ["name"]=> string(47) "Purchase Order Change Request - Buyer Initiated" } [11]=> object(stdClass)#15 (2) { ["id"]=> string(3) "864" ["name"]=> string(12) "Text Message" } [12]=> object(stdClass)#16 (2) { ["id"]=> string(3) "945" ["name"]=> string(25) "Warehouse Shipping Advice" } [13]=> object(stdClass)#17 (2) { ["id"]=> string(3) "997" ["name"]=> string(26) "Functional Acknowledgement" } } } }

After:

object(stdClass)#2 (1)  {
    ["GetDocTypeListResult"]=> object(stdClass)#3 (1)  {
        ["DocType"]=> array(14)  {
            [0]=> object(stdClass)#4 (2)  {
                ["id"]=> string(3) "180" 
                ["name"]=> string(49) "Return Merchandise Authorization and Notification" }
            [1]=> object(stdClass)#5 (2)  {
                ["id"]=> string(3) "810" 
                ["name"]=> string(16) "Customer Invoice" }
            [2]=> object(stdClass)#6 (2)  {
                ["id"]=> string(3) "816" 
                ["name"]=> string(28) "Organizational Relationships" }
            [3]=> object(stdClass)#7 (2)  {
                ["id"]=> string(3) "820" 
                ["name"]=> string(31) "Payment Order Remittance Advice" }
            [4]=> object(stdClass)#8 (2)  {
                ["id"]=> string(3) "824" 
                ["name"]=> string(18) "Application Advice" }
            [5]=> object(stdClass)#9 (2)  {
                ["id"]=> string(3) "830" 
                ["name"]=> string(41) "Planning Schedule with Release Capability" }
            [6]=> object(stdClass)#10 (2)  {
                ["id"]=> string(3) "840" 
                ["name"]=> string(21) "Request for Quotation" }
            [7]=> object(stdClass)#11 (2)  {
                ["id"]=> string(3) "846" 
                ["name"]=> string(24) "Inventory Inquiry/Advice" }
            [8]=> object(stdClass)#12 (2)  {
                ["id"]=> string(3) "850" 
                ["name"]=> string(14) "Purchase Order" }
            [9]=> object(stdClass)#13 (2)  {
                ["id"]=> string(3) "852" 
                ["name"]=> string(21) "Product Activity Data" }
            [10]=> object(stdClass)#14 (2)  {
                ["id"]=> string(3) "860" 
                ["name"]=> string(47) "Purchase Order Change Request - Buyer Initiated" }
            [11]=> object(stdClass)#15 (2)  {
                ["id"]=> string(3) "864" 
                ["name"]=> string(12) "Text Message" }
            [12]=> object(stdClass)#16 (2)  {
                ["id"]=> string(3) "945" 
                ["name"]=> string(25) "Warehouse Shipping Advice" }
            [13]=> object(stdClass)#17 (2)  {
                ["id"]=> string(3) "997" 
                ["name"]=> string(26) "Functional Acknowledgement" }
        }
    }
}
|improve this answer|||||
-1

The Tidy2 plugin does exactly what you want.

|improve this answer|||||
  • 3
    Can you add more information? – Jon May 29 '14 at 14:13
  • 3
    A link to developer's/distributor's website and some detail on plugin would be helpful – Art Gertner May 29 '14 at 14:15
  • All this did was wrap the code in an HTML body tag. :( – Michael Yaeger May 27 '17 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.