How to hide columns like the way we hide rows?
-
So I have some nested HTML that I am miffed about when I view it and see the massive amount of whitespace to the left. In the worst case it takes up half of my monitor. How can I hide it?
</div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>It’d be nice to tell Notepad++ to hide the giant mass of whitespace. I could reformat the HTML, sure, but I’m pretty sure Notepad++ as a very godlike text editor has this feature in it. Somewhere. Hopefully…?
-
XMLTools is a good plugin for working with XML and thus HTML, but there doesn’t seem to be a plugin command in XMLTools for doing exactly the thing you’re asking for.
However, it’s pretty easy to remove all the line-leading whitespace before an open or close tag in HTML: just use the find/replace form (Search Mode =
Regular expressions, Wrap Around checked) to Replace All instances of(?-s)^\h*(?=</?\w+)with nothing.For example, this would change
<foo> <bar> <baz> none of this leading whitespace will disappear <quz>note that all the whitespace before the "quz" close tag will NOT go away (because it's not line-leading) </quz> <zugen> <jugy> deepest indent </jugy> </zugen> </baz> </bar> more text blah blah <quz>more whitespace that won't go away </quz> </foo>to
<foo> <bar> <baz> none of this leading whitespace will disappear <quz>note that all the whitespace before the "quz" close tag will NOT go away (because it's not line-leading) </quz> <zugen> <jugy> deepest indent </jugy> </zugen> </baz> </bar> more text blah blah <quz>more whitespace that won't go away </quz> </foo> -
If you wanted to ensure that all open and close tags are at the beginning of a line, you could instead replace all
(?-s)(^)?\h*(?=</?\w+)with(?1:\r\n).See documentation on substitution conditionals to help understand that replacement, but basically this find/replace is saying “remove all whitespace before the close tag, and then if it’s not at the start of the line, add a newline before it”.
In this case,
<foo> <bar> <baz> none of this leading whitespace will disappear <quz>note that all the whitespace before the "quz" close tag will NOT go away (because it's not line-leading) </quz> <zugen> <jugy> deepest indent<deep>blah blah</deep> </jugy> </zugen> </baz> </bar> more text blah blah <quz>more whitespace that won't go away </quz> </foo>would be converted to
<foo> <bar> <baz> none of this leading whitespace will disappear <quz>note that all the whitespace before the "quz" close tag will NOT go away (because it's not line-leading) </quz> <zugen> <jugy> deepest indent <deep>blah blah </deep> </jugy> </zugen> </baz> </bar> more text blah blah <quz>more whitespace that won't go away </quz> </foo> -
@Mark-Olson Hi Mark,
I did consider a regex to delete whitespace before tags, but then how will I get the whitespace back after any edits are made? C-z works is too much potential for human error.
For the human error reason, I don’t want to eliminate whitespace, just hide it (by hiding the columns).
It sounds like this isn’t an existing feature in Notepad++. And someone did ask about it and created an issue, I just bumped the issue now: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14112
I don’t know if the forum etiquette here is to close a topic or leave it open… technically there’s no more help needed since there is nothing to do until someone does a PR, but this topic now effectively just links to an issue on the npp issues tracker as it can’t be done in npp the way I want it to be, as it stands.
-
If you need to quickly navigate to the tags of an HTML document while ignoring whitespace, maybe a tree view would help. From a quick trip to Google, it seems like XMLNavigator might be a reasonable option, although it hasn’t been updated in a few years. I haven’t used it myself, but if it seems interesting to me I may try to fork and update it.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login