How do I automatically trim trailing whitespace with Notepad++?

You should be able to do a regular expression find/replace in Notepad++ using a pattern like \s+$.

There are also a few options under menu Edit -> Blank Operations that may fit your needs.

Under the "Macro" menu there's an option for "Trim trailing and save". If you need to do a regular expression it may be possible to create a macro however I've never tried them.


Alt+Shift+S does what you want. In fact it also saves the file.

Update

As 10basetom noted, you can assign a different shortcut to this macro. You can control your shortcuts under Settings > Shortcut Mapper > [Macros].

enter image description here


The existing answers look old.

Try below path:

Notepad++ > Edit (menu) > Blank Operations > Trim Trailing Space