Community
    • Login

    Combine 2 files line by line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 7 Posters 5.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • astrosofistaA
      astrosofista @guy038
      last edited by

      Hi @guy038

      That’s right, the End key will get the same outcome, though I’m not sure it’s any easier to understand. Anyway, good catch :)

      By the way, shouldn’t all the multi-carets be shown in red? At least that’s what I expected to see, since I wanted them to stand out in the animation.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @astrosofista
        last edited by Alan Kilborn

        @astrosofista said in Combine 2 files line by line:

        shouldn’t all the multi-carets be shown in red? At least that’s what I expected to see,

        Curious, why do you expect this?
        Typically the caret related to the main selection is supposed to visually “stand out” from any secondary carets. Several Notepad++ functions act only on the main selection, so sometimes it is helpful to know which this is going to be before invoking the function.

        In Pythonscript, I do this to make the different carets stand out well:

            for e in (editor1, editor2):
                e.setCaretFore((0xFF, 0, 0))  # turn the main caret bright red for better visibility
                e.setAdditionalCaretFore((0, 0, 0))  # turn the secondary carets black for good visibility
        
        astrosofistaA 1 Reply Last reply Reply Quote 0
        • astrosofistaA
          astrosofista @Alan Kilborn
          last edited by

          Hi @Alan-Kilborn

          For a reason of consistency. I expected to see all carets in the same color but not in the same shade, just as if I set the caret color to black in the Style Configurator, then the secondary carets are shown in gray.

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @astrosofista
            last edited by Alan Kilborn

            @astrosofista

            So then how are you actually getting different colored carets and not just the same-base-color-but-different-shade effect?
            Maybe you don’t know and this is your question?

            Anyway, forgot to include the screenshot I made of my custom-colored carets; here it is:

            d16efd7d-e181-4f87-9f5e-4b9bf6dbc8f8-image.png

            astrosofistaA 1 Reply Last reply Reply Quote 0
            • astrosofistaA
              astrosofista @Alan Kilborn
              last edited by

              @Alan-Kilborn said in Combine 2 files line by line:

              So then how are you actually getting different colored carets and not just the same-base-color-but-different-shade effect?
              Maybe you don’t know and this is your question?

              That’s my question, yes.

              Concerning the screenshot, will try the code, though I will probably set all the carets to the same base color, just to check the effect.

              1 Reply Last reply Reply Quote 1
              • C
                Cooeeeee @astrosofista
                last edited by Cooeeeee

                @astrosofista I use a method similar to yours that works without any plugins (unless those are default plugins that I also have). I add blank lines to both the source and destination block (search: [\r\n]+ replace: \r\n\r\n. I then Alt+Shift block select the source block, cut, position the cursor on the first blank line in the destination and paste.

                C astrosofistaA 2 Replies Last reply Reply Quote 2
                • C
                  Cooeeeee @Cooeeeee
                  last edited by

                  @Cooeeeee GIF demonstrating the line interleave

                  1 Reply Last reply Reply Quote 1
                  • guy038G
                    guy038
                    last edited by guy038

                    Hello, @cooeeeee and All,

                    Ah…! Many thanks for that tip and work-around ! I didn’t even know that such an operation was possible ! Note that it’s works whatever the BetterMultiSelection plugin of @Dail is enabled or not ;-))

                    Note that you may shorten your regex S/R as below :

                    SEARCH \R

                    REPLACE $0$0

                    Best Regards,

                    guy038

                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @guy038
                      last edited by

                      @guy038 and others:

                      What allows it to work, is an odd(?) property of column blocks – the inability to copy line-endings.

                      Here’s some text before blocking out a column, note where the CRLF line-endings are:

                      809a4cf5-49cd-4d1e-9fd2-5c55363607cc-image.png

                      Now here’s the same text after a rectangular block is put into place; again note where the CRLF are (they’re outside the selection), especially on the empty lines:

                      4f9678ee-ce37-47ff-acc0-705ccf1a51b8-image.png

                      Note that none of the line-ending characters made it into the block.
                      Thus when this is copied and pasted, the originally empty lines are pasted as “nothingness”, allowing the technique by @Cooeeeee to work for merging data. Nice one.

                      1 Reply Last reply Reply Quote 3
                      • astrosofistaA
                        astrosofista @Cooeeeee
                        last edited by

                        Hi @Cooeeeee

                        I see. The point of my post was to simplify @Fernando-Sorensen’s method, because although ingenious, it requires several steps. The basic idea was to do everything without additional windows, be it a second editor, the column editor or a search window, that would block or cut off the flow of the operation.

                        The only thing that the BetterMultiSelection plugin is good for in my approach is precisely to insert the blank lines, an operation that standard multiselection cannot do - see @Alan-Kilborn’s post below - . But if the text already has blank lines interleaved, then the plugin is not necessary and, as your .gif shows, line interleaving can be done directly with standard multiselection.

                        Which is the best method? For the reasons detailed above and because I have nothing against third party plugins either - in fact, I think they are a great addition to Notepad++ and heavily use them - I still prefer mine, but I have no objection to people using the one they find best.

                        Thank you and, as always, have fun!

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors