I just started to use NetBeans, and am trying to work out how to:
Make it so that trailing whitespace is removed on save. I know that you can invoke it manually, but it’s annoying if you forget. Can it be done automatically on save? I want this done because it keeps the code neat, because it’s really annoying when you’re moving through code and the text cursor goes all over the place because of trailing whitespace you don’t see, and because trailing whitespace has unintended effects on HTML layouts and other stuff.
Make it so that tabs are automatically made into 4 spaces while you’re typing rather than converting on save, or, worse, only when manually invoked.
Type M-x delete-trailing-whitespace to delete all trailing whitespace. This command deletes all extra spaces at the end of each line in the buffer, and all empty lines at the end of the buffer; to ignore the latter, change the variable delete-trailing-lines to nil .
To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.
Some editors automatically remove trailing whitespace, some don't. This creates diff noise and can cause merge conflicts. You should coordinate with the people you're working with (colleagues, open-source crowd) what strategy everybody is using and make sure you all use the same strategy.
The STRIP function is similar to the TRIM function. It removes both the leading and trailing spaces from a character string.
For the first question, NetBeans 7.0+ has now a built-in solution. You can find it in:
Tools > Options > Editor > General > When saving files > Remove Trailing Whitespace: Never / Always / For Modified Lines Only
Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With