I'm using a Notepad++ macro to 'Trim trailing and save' files. And I have setup to [Ctrl]+[S] hotkey.

But, sometimes I'm editing files that I need to keep their spaces. Is it possible to set up a macro only for some file extensions? Or there is another way to auto apply Trim trailing spaces on save only for some file extensions?

Note: I use Notepad++ to edit php files but also MarkDown files that need blank spaces at the end of some lines.

Update: I'm using Notepad++ for Windows.


Use the "Trim Trailing and save" macro:

Macro -> Trim Trailing and save

The default shortcut is:

Alt + Shift + s

You should use python script to do that.

Write a script called during the startup.py script that register a call back on notification filesaved:

notepad.callback(saveFile, [NOTIFICATION.FILESAVED])

In the function saveFile, you check the extention. If the extension is valid, you can call trim trailing space function, then call save function.

  • 1
    I'm using Notepad++ on windows. This can be done on windows? Where to put the script? – Juan Antonio Tubío Jun 20 '15 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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