Removing Trailing Spaces
By Petr on Nov 24, 2009
Last week, when I was at the IPC 2009 conference, a some user ask me whether NetBeans removes trailing spaces. It was one question from many and I would like to clarify how it works in NetBeans 6.0 - NetBeans 6.8.
Basically it works automatically on save. So when you invoke Save action then the trailing spaces should be removed from the file. There are two exceptions, when the spaces are not removed from a line:
- The line wasn't changed. The main reason for such behavior is that usually you don't want to have unnecessary changes in the diff, if the files comes from a VCS. So unchanged lines are not touched and if there is a space at the end of such line, then is not removed. When you edit the line then the spaces are removed on save as well.
- The line where the caret is located. When you invoke Save action, then the position of the caret is not changed. But all trailing spaces after caret are removed.
If you want remove all trailing spaces in the file, you have to invoke action Remove Trailing Spaces from Source menu by hand.