Formatting Code In Notepad++ - Html - Stack Overflow

Just browsing Stack Overflow? Help us improve your experience. Sign up for research
    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs Formatting code in Notepad++ Ask Question Asked 14 years, 3 months ago Modified 1 year, 2 months ago Viewed 699k times 212

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.

Share Improve this question Follow edited Aug 23, 2017 at 19:20 mx0's user avatar mx0 7,06312 gold badges55 silver badges56 bronze badges asked Sep 3, 2010 at 11:58 darren's user avatar darrendarren 19.3k17 gold badges61 silver badges81 bronze badges 3
  • 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. – darren Commented Jan 24, 2011 at 10:36
  • 2 This needs a modern answer. None of these answers work anymore. – Philip Rego Commented Jan 5, 2018 at 19:39
  • 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++ – Muhammad Musavi Commented Jan 1, 2019 at 5:20
Add a comment |

15 Answers 15

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 131

TextFX -> HTML Tidy -> Tidy: Reindent XML

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

Share Improve this answer Follow edited Mar 26, 2014 at 10:21 thomaux's user avatar thomaux 19.7k10 gold badges80 silver badges104 bronze badges answered Sep 3, 2010 at 12:17 gablin's user avatar gablingablin 4,7686 gold badges35 silver badges48 bronze badges 11
  • 1 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 Commented Sep 13, 2010 at 14:54
  • 163 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. – darren Commented Feb 1, 2012 at 10:15
  • 2 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. – darren Commented Jun 24, 2012 at 16:09
  • 1 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. – Anthony Walsh Commented Feb 4, 2013 at 13:21
  • 4 The Tidy2 plugin will do the job, Plugins > Plugin Manager > Show Plugin Manager then add Tidy2.user1413338 Commented Oct 28, 2014 at 14:13
| Show 6 more comments 80

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.

Share Improve this answer Follow answered Apr 17, 2012 at 8:53 Dmitry Avtonomov's user avatar Dmitry AvtonomovDmitry Avtonomov 9,4394 gold badges35 silver badges47 bronze badges 7
  • 10 +1 This works great! Install the UniversalIndentGUI plugin and press Ctrl+Alt+Shift+J to format. – T_D Commented Jun 9, 2013 at 10:20
  • 1 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. – obesechicken13 Commented Jun 9, 2013 at 20:44
  • 2 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. – Stabledog Commented Nov 20, 2014 at 15:22
  • 1 though a plugin, it comes preinstalled in default Notepad++ installers – Dmitry Avtonomov Commented Nov 21, 2014 at 18:58
  • 3 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 ***? – mike rodent Commented May 29, 2017 at 17:36
| Show 2 more comments 23

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.

Share Improve this answer Follow edited Sep 6, 2013 at 21:45 john_science's user avatar john_science 6,5136 gold badges44 silver badges61 bronze badges answered Aug 11, 2011 at 16:35 user890332's user avatar user890332user890332 1,36115 silver badges16 bronze badges 3
  • 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. – Jo Smo Commented Jun 6, 2014 at 6:40
  • 1 I don't have a TextFX menu... what are you on about? – mike rodent Commented May 29, 2017 at 17:32
  • You will need to install it through the plugins manager. It's called TextFX Characters. – user890332 Commented May 30, 2017 at 18:25
Add a comment | 20

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.

Share Improve this answer Follow answered Jun 19, 2019 at 15:44 Grandizer's user avatar GrandizerGrandizer 3,0154 gold badges52 silver badges81 bronze badges 3
  • 4 This is the ONLY solution on this page that worked for me, and it works perfectly! – Don Kelley Commented Jan 31, 2020 at 23:11
  • 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 – Ashok Chhetri Commented Oct 25, 2021 at 10:29
  • It indents empty closed tags correctly, but not void tags, or closed tags with content. <closed></closed> 👍, <void> & <closed>text, CSS, or JavaScript</closed> 👎 – zer00ne Commented Feb 7, 2022 at 19:32
Add a comment | 11

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 Improve this answer Follow edited Mar 29, 2017 at 8:19 answered Sep 3, 2010 at 12:02 Thariama's user avatar ThariamaThariama 50.7k13 gold badges144 silver badges174 bronze badges 3
  • 25 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. – darren Commented Sep 3, 2010 at 12:13
  • macros are described here: stackoverflow.com/questions/362444/… – Thariama Commented Sep 3, 2010 at 12:56
  • 43 Haha all that and no shortcut for the question? Why post it? -1 – M H Commented Sep 15, 2015 at 17:24
Add a comment | 10

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.

Share Improve this answer Follow answered Apr 13, 2013 at 5:02 JackArbiter's user avatar JackArbiterJackArbiter 5,7852 gold badges28 silver badges34 bronze badges 0 Add a comment | 7

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

Share Improve this answer Follow answered Jun 7, 2012 at 7:43 panky sharma's user avatar panky sharmapanky sharma 2,13929 silver badges45 bronze badges 1
  • As of 2023 JSMin is the best answer for JS, its built into the plugins list, install any time. Select the region, click JS Format from the plugin menu. – ChrisAdmin Commented Sep 20, 2023 at 3:11
Add a comment | 5

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.

Share Improve this answer Follow edited Oct 25, 2021 at 22:31 answered Jul 23, 2014 at 2:40 user3413723's user avatar user3413723user3413723 12.1k6 gold badges60 silver badges67 bronze badges 3
  • Definitely not an answer to this question – nikodaemus Commented Oct 15, 2015 at 16:14
  • Is it possible to auto format PHP inside Netbeans? Do I need some additional plugin to do that? Thanks. – W.M. Commented Apr 30, 2016 at 12:04
  • 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. – user3413723 Commented Apr 30, 2016 at 12:41
Add a comment | 4

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

Share Improve this answer Follow answered Nov 2, 2020 at 11:11 NevetsKuro's user avatar NevetsKuroNevetsKuro 9368 silver badges18 bronze badges Add a comment | 3

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

Alt + Ctrl + Shift + B Share Improve this answer Follow answered Jun 5, 2019 at 12:14 itzmebibin's user avatar itzmebibinitzmebibin 9,4399 gold badges51 silver badges62 bronze badges 3
  • 3 I installed latest notepad++ but the short cut is not working for me. Can you provide another answer please. – Shashi Shiva L Commented Sep 28, 2019 at 9:26
  • In which version and on what content type is that shortcut supposed to work? Tried it in Notepad++ v7.7.1 with no effect.user166566 Commented Nov 20, 2019 at 7:11
  • 1 This is a shortcut added by XML Tools. – GrumpyCrouton Commented Aug 18, 2020 at 0:50
Add a comment | 2

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

Share Improve this answer Follow answered Sep 3, 2013 at 0:47 danny's user avatar dannydanny 3,2363 gold badges25 silver badges29 bronze badges 0 Add a comment | 2

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

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

Share Improve this answer Follow answered Feb 20, 2014 at 1:58 Will Wang's user avatar Will WangWill Wang 1131 silver badge6 bronze badges 0 Add a comment | 1

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

Share Improve this answer Follow answered Apr 11, 2019 at 19:30 Philip Rego's user avatar Philip RegoPhilip Rego 6524 gold badges25 silver badges36 bronze badges 3
  • Wrong answer, into the embedded plugin manager of Notepad++ can install and activate the functionality. IDE are not required. – Payedimaunt Commented Jun 14, 2019 at 14:53
  • "by itself". Have fun trying to get Notepad++ to format when you don't have access to install plugins. – Philip Rego Commented Jun 14, 2019 at 16:00
  • 2 @Payedimaunt , please provide the answer in detail. – Shashi Shiva L Commented Sep 28, 2019 at 9:30
Add a comment | -1

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.

Share Improve this answer Follow answered Nov 17, 2020 at 13:47 M SW's user avatar M SWM SW 95 bronze badges Add a comment | -1 Another Potential Solution

Okay, so it's been 12 years since this question was asked. I think that I've found a another acceptable solution, that is perhaps better for formatting files, using Prettier.

What is Prettier?

Prettier is described as: "an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary."

Prettier Supports the Following Languages

  • HTML
  • CSS, Less, and SCSS
  • JavaScript
  • TypeScript
  • JSX, Angular, Vue
  • JSON, Markdown, YAML

And a few others.

If You Want to Use Other Languages, You Can Either Use:

  1. Plugins made by the community to Prettier, which allow support for other formats such: Java, Rust, PHP, SQL, and others.
  2. Non-Prettier formatters supporting other languages such as clang-format (npm version) (C / C++ / Java / JavaScript / JSON / Objective-C / Protobuf / C#), or Black (Python).
How To Install
  1. You're going to need to install Node.js for this tutorial.

Note: There may be other work arounds for using the subsequent mentioned software without using Node.js. But to keep this tutorial simple and the fact that Node.js already carries widespread familiarity among developers, I'm going to be using this software without explaining how to install it.

  1. After installing Node.js, install prettier globally to your system, allowing yourself to run prettier anywhere from the command line.
# NPM is the package manager used by Node.js # And --global allows you to use prettier anywhere on your local computer. npm install --global prettier # To install other plugins (example): npm install --g prettier-plugin-rust prettier-plugin-java # To Install clang-format using NPM npm install -g clang-format # Usage Examples prettier --write jquery-min.js # Formatting a JavaScript file clang-format -i Test.cpp # Formatting C++ file
  1. On Notepad++, install a plugin called NppExec from Menu> Plugins Admin...> Available> NppExec.
  2. You can now run NppExec by either pressing F6 or by clicking Menu > Plugins > NppExec > Execute NppExec Script...
  3. Now you should have a window pop up, giving you the option of executing a command.
  4. You can either use prettier on a (1) specific file or (2) all files in a folder or (3) all files in a directory recursively.
  5. You can always reload a file after it's better overwritten by Prettier using Ctrl+R, and enabling the following setting: Menu > MISC. > Update silently.
Commands and Screenshots of NppExec + Prettier. REM Using Prettier on Current File (use cmd or powershell /c) cmd /c prettier --write "$(FULL_CURRENT_PATH)" REM Using Prettier on Current Folder (a single asterisk) pwsh /c prettier --write "$(CURRENT_DIRECTORY)\*" REM Using Prettier on Current Directory Recursively (double asterisk) pwsh /c prettier --write "$(CURRENT_DIRECTORY)\**"

Install NppExec Plugin

Install NppExec

Running NppExec Plugin

Running NppExec Plugin

Executing Commands on NppExec

Executing Commands on NppExec

Share Improve this answer Follow answered Nov 13, 2022 at 5:48 Moh's user avatar MohMoh 291 silver badge5 bronze badges Add a comment | Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

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

  • The Overflow Blog
  • Your docs are your infrastructure
  • Featured on Meta
  • More network sites to see advertising test [updated with phase 2]
  • We’re (finally!) going to the cloud!
  • Call for testers for an early access release of a Stack Overflow extension...

Linked

28 Reformat Code in Notepad++ 190 What does the double-asterisk (**) wildcard mean? 99 Notepad++ htmltidy - unable to find libtidy.dll 39 How to write macro for Notepad++? 4 format/beautifier/reindent underscore code block 0 When "viewing source", some sites have neat markup, some sites don't. Why? (pic attached) 0 notepad++ xml tag in one line 1 How to automatically add spaces between appropriate characters in Notepad++ 1 one button to change layout in notepad++ 1 Contemporary Solution for Formatting HTML in Notepad++ See more linked questions 5 HTML Formatting 2 Reformatting HTML 13 How to format a document in Notepad++ 1 Code formatting with NP++ 15 How can I indent HTML or PHP code in Notepad ++ editor? 0 Formatting HTML code 0 Notepad ++ shows html code in red 95 How to indent HTML tags in Notepad++ 0 How to add CSS to my HTML code on Notepad++ 0 How can format HTML with Visual Studio Code?

Hot Network Questions

  • What exactly is the cornerstone that Mark 12:10 speaks of?
  • Is “thing” a good category?
  • What is this Stardew Valley item?
  • How to design for API use cases that need different data from the same table?
  • If someone’s words are likely to be disregarded, how to describe the quality of “meaning” they lack?
  • The British used to (still?) classify their guns by weight in pounds rather than caliber. Was that a constant across shell types?
  • Static vs dynamic certificate pinning
  • Is Holy Terra Earth?
  • Sorites paradox and emergence
  • Question on Lorentzian geometry
  • Groups with no proper non-trivial fully invariant subgroup
  • Group cohomology valued in a bimodule
  • Why is it safe to soak an electric motor in isopropyl alcohol but not distilled water?
  • Responsibility for clearing gutters? (Landlord and Tenant Act 1985)
  • What's a good way to append a nonce to ciphertext in Python for AES GCM in Python?
  • Are mental images of mathematical entities persistent?
  • Counting birds outside my house
  • How to attribute authorship to personal non-academic friend who made significant contributions
  • Why is a pure copper cathode necessary in the electrolytic refining of copper?
  • It will not last
  • Why is bash startup executed under non-interactive ssh
  • Wouldn't the ban of TikTok violate freedom of speech?
  • Student is almost always late, and expects me to re-explain everything he missed
  • Deutsche Bahn Berlin: can I use a different departure station?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Block Tekstu