Hidden NetBeans Feature: Show Spaces in Editor
By Geertjan on Jan 18, 2012
A really cool feature that I didn't know about until a few hours ago. Go to the main NetBeans menu bar and choose "View | Show Non-printable Characters". And now I can see the spaces in the editor:
The above is in the Java editor. Here is the HTML editor, with spaces:
Really handy to see the spaces (and the carriage returns, as well as the tabs). I made the above discovery while e-mailing with NetBeans Dream Team member Ryan de Laplante. He said that IntelliJ IDEA shows the spaces in the editor, while NetBeans doesn't. Some googling later, I found that NetBeans does, after all, have this support.
It appears that the spaces are visible in the editor for the first time in NetBeans IDE 7.1. At least, I invoked the same action as described above in 7.0.1 and then saw the carriage returns, but not the spaces. (And here's someone else who's found the same thing to be true.)
It's also possible to change the color of the non-printable characters, i.e., you could make them light grey. (But non-printable characters in HTML files do not change color as specified, so that's a bug.) Go to Tools | Options | Fonts & Colors and then go down the Category list until you find "Whitespace". Ryan commented on this that in IntelliJ IDEA "the non-printable characters are shown in a very light shade of grey so I can leave the feature turned on all the time and barely notice it unless I specifically want to look at it. In NetBeans I was able to change the color of the whitespace characters to a light grey too. That would be a nice default."
A second point that Ryan makes about the IntelliJ IDEA implementation of this feature is: "They don't show the line break character… they know that I'm only interested in whitespace characters. Maybe instead of enabling a 'Show non-printable characters' feature, I could enable a 'Show whitespace characters' feature."
And, finally, thus far, I've been unable to distinguish an EOL character from a carriage return (as also pointed out here).
But, clearly, aside from these quibbles, which I think would be nice enhancements for an upcoming release (see the list of issues I added in the comments to this blog entry), it's really great to see the spaces visibly in the editor. Makes it much easier to align one line with the next.
Other support for spaces include Tools | Options | General | Remove Trailing Whitespace, where you can specify under which condition (Never, Always, From Modified Lines Only) the last space, if any, should automatically be removed when the file is saved. Also, if you go to Tools | Options | Formatting | Java | Spaces, you can specify where a space should automatically be entered. (There's a similar option there where you can specify where a blank line, tabs, and indents should automatically be added, e.g., before/after methods, etc.)
NetBeans IDE: where the perfectly customized editor is only a space away...