Notepad++ "Compress whitespace" effect

7

0

I'm looking for a mechanism within notepad++ to replace runs of consecutive whitespace with a single space, like the "Compress whitespace" command in notepad2.

Essentially, in regex form:

s/\s+/ /g

I know I can do it with the find-replace form, but I would prefer soemthing that I can bind to a keyboard sequence.

EDIT

Find and replace cannot be recorded as a macro in some versions of Notepad++. Update to the latest if you have trouble.

tylerl

Posted 2011-02-14T09:04:39.097

Reputation: 2 064

Wouldn't \s also match end of line characters? I'd think you'd want to find + (space plus) and replace with (space) – Zachary Scott – 2016-07-29T19:58:59.137

Answers

4

You should be able to set this regex up as a macro and then bind the macro to a shortcut.

Settings > Shortcut mapper... > Macros

ChrisF

Posted 2011-02-14T09:04:39.097

Reputation: 39 650

For whatever reason, I can't save the act of using the find-replace dialog as a macro. – tylerl – 2011-02-14T19:16:24.937

@tylerl when I do start recording, then do a find/replace of abc to xyz, then stop recording. then write in abc , then click macro..playback, it plays it back. so it does record. and I see an option to the current macro – barlop – 2011-02-14T20:31:10.230

@barlop - Doesn't work here. I do start recording, then find-replace, then stop-recording -- my macro isn't saved. It's as if I hadn't done a find-replace. The Playback option is grayed out. – tylerl – 2011-02-14T23:02:28.360

@barlop - Updated notepad++ to the latest version, and it works now. Thanks. – tylerl – 2011-02-14T23:05:19.560

7

Edit > Blank Operations > Remove Unnecessary Blank and EOL

Not sure if that's a default feature or plugin, but there's always a million plugins to do anything else.
The TextFX Plugin is worth a look as well.

David Hobs

Posted 2011-02-14T09:04:39.097

Reputation: 231

Wonder how to do it without removing EOL but still compress space (without doing regex find + (space plus) and replace with (space)? – Zachary Scott – 2016-07-29T20:01:29.977