Split lines at the vertical line

Stephan
2014-05-28
2015-01-12
  • Stephan
    Stephan
    2014-05-28

    Notepad++ has this nice "Split lines" option, which splits the line at the point where my view ends. However, I would love to see an option that does something like "split lines at cursor position" or "split lines at vertical line" (for splitting the lines at the vertical line that I have enabled in my view). This would be very useful for splitting long comments fast and easy. I now have to manually move my cursor to the vertical line and press [enter] for each line break that is needed.

     
  • dail8859
    dail8859
    2014-05-28

    I totally agree. I posted this idea a while ago about splitting lines on the vertical edge line. From my understanding it shouldn't be to hard to implement in the N++ source code.

     
  • THEVENOT Guy
    THEVENOT Guy
    2014-05-29

    Hello, Stephan and dail8859,

    I do agree that would be a nice improvement ! But, in the meanwhile, you just can achieve the same behaviour with a simple search/replacement, using regular expressions :-)

    So, in regular expression mode, run the Search/Replacement below :

    SEARCH : .{n}(?!\R)

    REPLACE : $0\r\n

    Of course, you must replace the number n with the maximum number of characters per line, you want to !

    Notes :

    • The Search regex is looking for n standard characters exactly, IF not followed by EOL character(s), due to the negative lookahead (?!\R), which MUST be verified, although it's NOT a part of the found regex.

    • The Replace regex re-write the totality of these n matched characters ( $0), followed by a Windows EOL ( \r\n)

    • The DOT represents any single character, different from, either, the \r, the \n or the \f character

    • The form \R represents, either, the two characters \r\n of an Windows EOL, the character \n of an Unix/OSX EOL or the \r character of an old MAC EOL

    • But, in the Replace regex, write $0\n, if your file is an Unix file


    Now, let suppose that you prefer the Notepad++'s wrap behaviour, which splits text between two words ONLY, instead of splitting lines inside a word !

    This time, use, preferably, the Search/Replacement below :

    SEARCH : .{1,n-1}((\h)|\R)

    REPLACE : $0(?2\r\n)

    Like the previous S/R, you must change the expression n-1, by the appropriate number !

    Notes :

    • The Search regex try to match the longest string of standard characters, up to n-1 characters, followed by, either, an horizontal space character ( \t, SPACE or \xA0 ) or EOL character(s)

    • In the Replace regex, the form (?2... ) is a conditional replacement : the characters, after ?2, will be written ONLY IF the group 2 exists

    • If the matched characters end with an horizontal space \h ( the group 2 ), the Replace regex re-write the totality of the regex ($0 : the n-1 characters AND the horizontal space ) and, as the group 2 exists, write \r\n ( the Windows EOL for splitting ! )

    • If the matched characters end with an EOL \R, the Replace regex re-write the totality of the regex ( $0 : the n-1 characters and the EOL characters ) but, as group 2 is missing, DON'T add the final EOL


    So, Stephan, if we consider all the text of your post, as an unique line , we obtain :

    • With the 1st S/R :

    Notepad++ has this nice
    "Split lines" option,
    which splits the line a
    t the point where my vi
    ew ends. However, I wou
    ld love to see an optio
    n that does something l
    ike "split lines at cur
    sor position" or "split
    lines at vertical line
    " (for splitting the li
    nes at the vertical lin
    e that I have enabled i
    n my view). This would
    be very useful for spli
    tting long comments fas
    t and easy. I now have
    to manually move my cur
    sor to the vertical lin
    e and press [enter] for
    each line break that i
    s needed.

    • With the 2nd S/R :

    Notepad++ has this
    nice "Split lines"
    option, which splits
    the line at the point
    where my view ends.
    However, I would love
    to see an option that
    does something like
    "split lines at cursor
    position" or "split
    lines at vertical
    line" (for splitting
    the lines at the
    vertical line that I
    have enabled in my
    view). This would be
    very useful for
    splitting long
    comments fast and
    easy. I now have to
    manually move my
    cursor to the vertical
    line and press [enter]
    for each line break
    that is needed.

    Let suppose, Stephan, that the four sentences of your post are followed by an EOL
    ( \r\n )
    . We get, now :

    • With the 1st S/R :

    Notepad++ has this nice
    "Split lines" option,
    which splits the line a
    t the point where my vi
    ew ends.
    However, I would love t
    o see an option that do
    es something like "spli
    t lines at cursor posit
    ion" or "split lines at
    vertical line" (for sp
    litting the lines at th
    e vertical line that I
    have enabled in my view
    ).
    This would be very usef
    ul for splitting long c
    omments fast and easy.
    I now have to manually
    move my cursor to the v
    ertical line and press
    [enter] for each line b
    reak that is needed.

    • With the 2nd S/R :

    Notepad++ has this
    nice "Split lines"
    option, which splits
    the line at the point
    where my view ends.
    However, I would love
    to see an option that
    does something like
    "split lines at cursor
    position" or "split
    lines at vertical
    line" (for splitting
    the lines at the
    vertical line that I
    have enabled in my
    view).
    This would be very
    useful for splitting
    long comments fast and
    easy.
    I now have to manually
    move my cursor to the
    vertical line and
    press [enter] for each
    line break that is
    needed.


    You'll find good documentation, about the new Boost C++ Regex library ( similar to the PERL Regular Common Expressions ) used by N++, since the 6.0 version, at the TWO addresses below :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    The FIRST link explains the syntax, of regular expressions, in the SEARCH part

    The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part

    Cheers,

    guy038

     
    Last edit: THEVENOT Guy 2014-05-29
  • that's a keeper! thank you!