The Computer Oracle

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

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: The World Wide Mind

--

Chapters
00:00 How Do I Automatically Trim Trailing Whitespace With Notepad++?
00:36 Accepted Answer Score 113
01:02 Answer 2 Score 94
01:24 Answer 3 Score 5
01:48 Answer 4 Score 6
02:17 Thank you

--

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

--

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.