Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

Is there a way to re-indent a block of code? I'm looking for something similar to Ctrl+Shift+F in Eclipse (Auto-Format/Indent).

To be clear,

I already know how to format XML outside of Notepad++ (Eclipse works fine, as mentioned) so I don't need a bunch of links to other XML-formatting tools.

I'm specifically working with XML and HTML.

Ideally, there's a keybinding as convenient as the one in Eclipse, so I don't have to break my workflow.

I already know about NppAutoIndent - it won't work, as I'm working with XML, HTML, and CSS.

3 Answers

0 votes
by (40.7k points)

If you are working on 6.3.2 version, then you can use XML Tools.

First, Install XML Tools via the Plugin Manager. Then use the shortcut Ctrl+Alt+Shift+B (or menu -> Plugins -> XML Tools -> Pretty Print)

For older versions, you can follow these steps: menu -> TextFX -> HTML Tidy -> Tidy: Reindent XML.

0 votes
by (37.3k points)

Below are steps to Auto-Format/Indent XML in Notepad++

Step 1:  Open  your XML file with Notepad++

Step 2:  Navigate to the “Plugins” menu option, then choose “Plugins Admin” from the dropdown option.

Step 3: Search “XML Tools,"  then check-mark it, and click on Install.

Step 4: Confirm the installation

Step 5: Then restart Notepad++, again go back to the  “Plugins” menu, and select XML Tools.       

Step 6: Click on Pretty Print to auto-format the XML file.

For HTML, the process is the same, but you can use some HTML-specific beautifier or plugin like the XML tool Plugin, TextFX plugin, or HTMLTidy tool for better formatting.

0 votes
by (1.1k points)

Among many of the Notepad++ plugins, the one which comes in handy for formatting and re-indent of XML and HTML codes is the XML Tools. Below is the practical advice on how you can set it up and use it to the maximum:

Step 1: Install the XML Tools Plugin  

  • Open Notepad++.  

  • Select Plugins > Plugins Admin.  

  • Find and tick XML Tools from the list.  

  • Hit Install and close Notepad++ if a prompt appears.  

Step 2: Format Your XML/HTML  

  • As seen with the installation of the XML tools, there is no code that makes it hard to format thanks to the formatting features provided:

  • Access the XML or HTML document that needs reformatting.  

  • Select the piece of the code that you would like to indent (or you can also indent the whole text).  

  • Click on Plugins > XML Tools > Pretty Print (XML only – uses line breaks) or Pretty Print (applies to HTML).  

  • Your text will be automatically reindented and formatted.  

Keybinding  

The downside is that there is no default keybinding that uses the Pretty Print in the XML Tools but you can make one:

  • Select Settings > Shortcut Mapper.  

  • Search for the command Picture-in-Picture in the XML Tools area.  

  • Choose it and then press Modify to assign your desired key binding.  

Alternative: Using Notepad++'s Built-in Indentation  

In case you only need to indent the document to a certain degree but do not want to install any plugins:

  • It is possible to highlight large sections of code and use the indent shortcuts Tab and Shift + Tab respectively.  

  • This is still better compared to basic unformatted edits although it is not as systemized as Eclipse’s Ctrl+Shift+F.  

Conclusion  

The best way to format using XML and HTML while on Notepad++ is to use the XML Tools plugin. As such it is advisable to create a custom keybinding in order for it to be usable like it does in Eclipse.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 18, 2019 in Java by Shubham (3.9k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...