I like the notepad++, but permanently have some inconveniences.
Because there's no way to automaticly remove trailing space from every line. Using a command from the "Edit" menu is a long way to do such a simple task.
I would be appreciated if some day this feature is implemented.
What are you talking about? I've been using this feature since v4.8. You just have to use Shortcut Mapper to assign Ctrl+S to it.
It's called Edit -> Trim trailing spaces.
Are you serious?!
I've been using this product for over 4 years (if not longer) and I have never noticed this feature before. Yikes! The amount deletes I could of saved is huge!
- Bob (who feels like an idiot now)
Thanks for your advice.
In my version of Notepad++ there's a macro called "Trim trailing and save" with the short cut Alt+Shift+S. Obviously it has appeared during installation. It's relatively convinient.
It's strange to me that trailing spaces irritate almost nobody. I hate these useless charactars. For ex. because when whant to delete a line I don't know how many times should I press Del before it's actualy deleted. I never know should I press Del, Backspace or select the line before deleting.
In any case thanks.
In case you're not familiar with these standard shortcuts, try Ctrl+Del, Ctrl+Backspace - makes trailing spaces a lot less annoying :)
But it seems to me that the ability to trim trailing spaces ought to be a configurable feature of every text editor. Especially of an editor for programmers.
> But it seems to me that the ability to trim trailing spaces ought to be a configurable feature of every text editor. Especially of an editor for programmers.
It IS configurable, especially BY programmers. Just think outside the box a little and move the "Ctrl+S" shortcut from "Save" to "Trim trailing and save".
Partially I may be satisfied because trailing spaces can be easily removed during saving.
But I would like to have trailing spaces removed immediately after a line is typed or pasted from another source.
There are a few cases when annoying spaces may appear. E.g.
- when I started to type some spaces and changed my opinion to continue this line;
- when I divide a line on two;
- when I paste some text from "bad" source.
And this ability is absent.
I think NppScripting or Python Script would allow you to schedule tasks (like trimming whitespace) every n seconds and before each save.
Otherwise, you can change the Save shortcut to something and bind the Trim trailing space and save macro to Ctrl-S.
Trim trailing and save should be the default, with an option in the dialog to prevent it in the rare case it is unwanted.
"Oh, you can just do this four-click process to fix it… "
While nice that the possibility exists, modifying a keybinding is not optimal, because:
- there is no language or markup that utilizes trailing whitespace.
- it creates noise in diffs and version control
- it wastes bytes
- it wastes time.
Perhaps those with time to kill don't mind an extra thing to worry about but to those of us who have multiple copies of n++ installed on VMs and computer labs, we don't appreciate having to worry about an additional non-useful detail on every copy we use. Is it enabled on this copy? What a waste of time, to no appreciable benefit.
In short, every professional editor provides this option directly, it's time for n++ to also. Defaults matter.
I just notice that if I use this macro with the cursor in the middle of a line it adds ten spaces at the cursor!
I just tried, and did not observe this undesired behaviour. Does it still happen if you rename your pugins directory to say "lugins"? I'm sure there is something interfering.
Hi, now that you mention it, it only happens on one of my machines. Nott sure why. Newest n++, renaming plugins had no effect.
Just my 15 cents...
I used UE before N++ (long time ago) and I remember UE automatically would have trimmed trailing slashes when saving a file (as an option in settings, of course). N++ would be great to have this implemented, saving us from forgetting to explicitly trim those extra buggy spaces introduced, accidentally by copy&paste God knows from which source.
That is different than the hints above (I mean the Ctrl-S and Macro suggestions). Thanks.
I've just added this code to startup.py:
def doRemoveTrailingWhiteSpaces(contents, lineNumber, totalLines):
contents = contents.rstrip ('\n\r')
stripped_contents = contents.rstrip ()
if stripped_contents != contents:
pos = editor.positionFromLine (lineNumber)
editor.setTarget (pos + len (stripped_contents), pos + len (contents))
pos = editor.getCurrentPos ()
line = editor.lineFromPosition (pos)
indent = pos - editor.positionFromLine (line)
# preserving current position
new_line = editor.getLine (line)
if indent >= len (new_line) - 1:
new_pos = editor.getLineEndPosition (line)
new_pos = editor.positionFromLine (line) + indent
And in "plugins->python script->configuration" I've chosen initialisation "ATSTARTUP". It works fine, though sometimes N++ crashes and I can't seem to figure out why for now (though I noticed a lot of garbage I've been printing to console while copy & pasting it here, maybe that was the cause :D ). Hope it will be useful to somebody))
EDIT: I optimized it a little so all the lines wouldn't be replaced on every save and also thus spellchecker underlines wouldn't be flickering.
why do you need this python script? Is default ALT-SHIFT-S macro not sufficient for trimming extra white space?
No that's actually fine, I just didn't notice it, my bad :)
Is there any progress on this?
This should really be configurable. All this workarounds are nice but if you expect a team to do this then you can't expect them to all do these things.
You can use this macro :
<Macro name="Trim Trailing and save" Ctrl="yes" Alt="no" Shift="no" Key="83">
<Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
<Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
It trim trailing space and save the file. Shorcut Ctrl+S is used to replace the standard save fonction.
It would be even better if it could be configured depending on the file type. It's done very nicely in TextPad. But in NP++, the whole configuring would have to be revamped to achieve this.
Notepad++ support for this is actually really good:
CTRL+S <-- regular save, no trimming
CRTL+SHIFT+S <-- save and trim whitespace
Just use them as needed.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.