The Computer Oracle

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

Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Thinking It Over

--

Chapters
00:00 Question
00:48 Accepted answer (Score 105)
01:20 Answer 2 (Score 87)
01:51 Answer 3 (Score 7)
02:07 Answer 4 (Score 6)
02:48 Thank you

--

Full question
https://superuser.com/questions/699382/h...

Question links:
[Eclipse]: http://en.wikipedia.org/wiki/Eclipse_%28...

Accepted answer links:
[regular expression]: http://en.wikipedia.org/wiki/Regular_exp...

Answer 2 links:
[image]: https://i.stack.imgur.com/atHrD.png

Answer 4 links:
[EditorConfig]: http://editorconfig.org/

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#notepad++ #tabs #whitespace

#avk47



ACCEPTED ANSWER

Score 113


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.




ANSWER 2

Score 94


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




ANSWER 3

Score 6


Plugins > Plugin Manager > Show Plugin Manager
Under the Available tab, select EditorConfig and click [Install]

Add an .editorconfig file to the folder (name it .editorconfig. to avoid Windows error "You must type a filename" - the last dot will be removed)

# trims trailing whitespace for all files; filter like [*.{json,xml}]
[*]
trim_trailing_whitespace = true

EditorConfig can also specify encoding, indent and newline character(s), etc.




ANSWER 4

Score 5


I changed the shortcuts to find a solution to this. I removed the save shortcut (shortcut mapper -> main menu -> save) and mapped Ctrl+S to the "Trim Trailing and Save" macro (shortcut mapper -> macros -> trim trailing and save). This way the macro replaces the save functionality and there's no need to remember the Alt+Shift+S shortcut.