"Remove Unnecessary Blank and EOL" ?

  • I’ve been trying to pin down what the Remove Unnecessary Blank and EOL menu item does, exactly. It seems like this is close, but not quite:

    Find (\h*\R)+
    Replace with single space
    Wrap around on
    (regex mode of course)

    Anybody know EXACTLY what this command does?

  • @Alan-Kilborn

    the menu item “Remove Unnecessary Blank and EOL” has id IDM_EDIT_TRIMALL (see Notepad_plus.rc)

    from NppCommands.cpp it calls doTrim(lineTail); and doTrim(lineHeader); as two passes (see Notepad_plus.cpp)

    doTrim(lineHeader); search string:

    env._str2Search = TEXT("^[	 ]+");

    doTrim(lineTail); search string:

    env._str2Search = TEXT("[	 ]+$");

    replace string for both:

    env._str4Replace = TEXT("");

  • Hello, @alan-kilborn, @meta-chuh, and All,

    After some tests, I deduced that the Edit > Blank Operations > Remove Unnecessary Blank and EOL operation is equivalent to the two regex S/R, below, run consecutively !

    • First, all leading and trailing tabulation and/or space character(s) are deleted, with the regex :

      • SEARCH ^[\t\x20]+|[\t\x20]+$

      • REPLACE Leave EMPTY

    • Secondly, any line-break ( Windows, Unix, or Mac ) is changed into a single space character, with the regex :

      • SEARCH \R

      • REPLACE \x20

    Notes :

    • This option and the regexes preserve the space and/or tabulation characters, when located between words or strings

    • The two S/R cannot be run simultaneously ! Indeed, if the previous match was, for instance, a line-break ( \R ), so changed into space, then a ^[\t\x20]+ match cannot occur anymore as the assertion ^ cannot be found :-((

    Best Regards,


  • @Meta-Chuh and @guy038

    Thanks for your inputs!

    @guy038 said:

    The two S/R cannot be run simultaneously !

    Well, say one wanted to recreate the Remove Unnecessary… functionality in a single regex operation. One could simply record a macro with @guy038 's two replacement operations…then when the user runs a single operation (the macro), two operations are done.

    I’m pointing this out because I often combine multiple regex replacement operations into a macro so that it appears to be a single simple operation, and other readers might not know that you can do this.

  • @Alan-Kilborn

    … and other readers might not know that you can do this.

    after this sentence part, i’m not sure anymore if, by asking the question:

    Anybody know EXACTLY what this command does?

    you wanted to know, what the command does programmatically for yourself, or if you wanted to know what it does at all, from a user perspective.

    for you, i guess the answer was suitable, but for normal users, the answer would be rather explaining what it does:

    Remove Unnecessary Blank and EOL removes all indentation, empty lines, and merges the whole file into one single line.

    (not quite accurate, but probably being the more understandable explanation, than to say: it removes all leading/trailing white spaces and line feeds of every line of a document)

    please keep me informed for who you intended this info to be for, as i am confused … again ;-)

  • @Meta-Chuh said:

    please keep me informed for who you intended this info to be for

    Hmmm, well it started out one way (Remove Unnecessary…) and then went almost a totally different way (a maybe enlightening technique for making multiple replacement operations appear like one action via macro record). Two really different things. That’s all.

    Often posters here (myself included I guess) bend over backwards trying to help someone with a complicated regex replacement that might be made much simpler with a multistep replacement. Because macros can be named, and simple replacements can’t (unlike with other text editors) but can be when they are recorded in a macro, I’m going to think better of and make more use of this kind of thing in the future. Maybe not revolutionary, but I for one haven’t been thinking this way in the (distant) past. It’s been more of a recent-past fetish (wrong word but can’t think of better ATM!) of mine.

  • Hi, @alan-kilborn, @meta-chuh, and All,

    UPDATED on 05 12 2019 : I made the regex, below, more accurate as I changed the \h syntax by the more strict one [\t\x20]

    When run consecutively, my two previous regexes do simulate the Remove Unnecessary Blank and EOL option !

    Of course, Alan, my initial goal was to find an unique regex S/R ! So, I thought again about this problem and, after additional tests, I finally found out a solution :

    SEARCH [\t\x20]*\R[\t\x20]*

    REPLACE \x20

    Thus, from the search regex, it’s easy to transpose it in natural speech :

    The Remove Unnecessary Blank and EOL option replaces any kind of line-break, possibly surrounded by, either, tabulation and/or space character(s), with a single space character ;-))

    Indeed, Alan, it’s valuable to remember that multiple regex S/R can be recorded, one after another, in a single macro ! It’s just that, most of the time, I simply re-invent the regular expression(s), necessary for my current work, if the overall regex(es) is/are not so complicated, of course ;-))



  • So, thanks everyone for contributing. I think it has now officially been beaten to death. I’ll mark as SOLVED now…


    I have one final question, and this one is for @donho (and of course will never be answered, and really is rhetorical anyway), and this is: What gives you the right to decree that these things are “unnecessary”?


Log in to reply