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

4 Answers 4

up vote 17 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

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

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

share|improve this answer
1  
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

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.