Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I don't want to delete the empty lines completely, but I want to remove the tabs and whitespaces in them. Eclipse usually does it (through a preference setting I guess) when we save the file.

For example, the file before saving ($ = end of line):

def shuffle(list):$
    import random $
    $
    random.shuffle(list)
    $
$

... and when I save this in the editor, Eclipse does the following:

def shuffle(list):$
    import random$
$
    random.shuffle(list)
$
$

Is this possible in Notepad++?

share|improve this question

6 Answers 6

up vote 18 down vote accepted

You should be able to do a regex find/replace in notepad++ using a pattern like \s+$.

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

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

share|improve this answer
3  
yes in my version of Notepad++, there's an Edit -> Trim Trailing Space, but can I trigger that automatically for every save? –  Srikanth Jan 9 '14 at 18:36
2  
There's an option for "Trim trailing and save" under the Macro menu –  johanno Jan 9 '14 at 18:39
7  
I have bound the Ctrl+S key to the Macro -> Trim Trailing and save option, using the Settings -> Shortcut Mapper... option. This is much better than having to remember to run the macro all the time. :) –  Darthfett Jan 9 '14 at 22:54
1  
I am not able to find Macro -> Trim Trailing and save... Am I just too blind or do I have to do something to make pre-defined macros available? –  NobodysNightmare Nov 26 '14 at 7:48
1  
nvm... created the macro myself ^^ –  NobodysNightmare Nov 26 '14 at 7:53

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.

share|improve this answer
2  
To strip trailing spaces when you save: (1) Remove the default Save shortcut (Ctrl+S), then (2) assign the "Trim Trailing and save" macro to Ctrl+S. –  10basetom Mar 3 at 4:33

Control+f -> Switch to replace ->

Find what: \t\r

Replace with: \r

Make sure Extended search mode is on, then replace all.

EDIT: After reading the question again, I realize you want to save as well. In this case, johanno has the correct solution. Macro -> Trim Trailing and Save works as specified.

share|improve this answer

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.

share|improve this answer

In order to preserve the existing menu commands, map (previously unassigned) Ctrl+T to trim trailing spaces. Then, do Ctrl+T and Ctrl+S together.

This lets you make a small change to a file without confusing text comparison utilities and source control programs by changing (potentially) hundreds of lines.

share|improve this answer

I changed the shortcuts to find a solution to this. I removed the save shortcut (shortcut mapper -> main menu -> save) and mapped "control + 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.