Combine 2 files line by line

  • Hi @Fernando-Sorensen and All:

    Yet another way to combine two blocks of text. It’s really easy to implement and requires just the multi-edition preference enabled and the BetterMultiSelection plugin activated, which you can download and install via the Plugins Admin.

    Firstly an animation and below a step by step description:


    1. Place the caret at the beginning of the second text block, which will be the inserting text.
    2. Do a block selection, that is, mouse-click at the left of character 2 and then another mouse-click at the end of the same block, but this time while pressing Shift + Alt.
    3. Copy the selected block (Ctrl + C).
    4. Go to the first character of first block text (Ctrl + Home) and mouse-click at the left of the first 1.
    5. Insert a multi-selection by pressing Shift + Alt + Arrow Down 4 times, till the bottom line of the text block.
    6. Press Arrow Down one more time (without Shift or Alt) in order to move the multi-selection one line down.
    7. Press Enter to add five lines to the text block.
    8. Paste (Ctrl + V) to combine both text blocks.

    That’s all. Hope you like it.

  • Hi, @astrosofista and all,

    A small variant :

    At step 6, press the End key. I think it’s easier to understand ;-))



  • So, really @astrosofista has found some amazing uses for the BetterMultiselection plugin.
    It makes one wonder, why isn’t this in Notepad++ itself (without need for the plugin)?
    @dail 's work with the plugin is really great, but why do we even need a plugin?
    I guess it would need to be in Scintilla, but these actions just make so much sense I wonder if the capabililty IS in Scintilla, and just not enabled in Notepad++'s use of Scintilla?

  • @Alan-Kilborn

    The newer versions of scintilla (which N++ is using) has a bit better support. However it still doesnt match what my plugin provides.

    I think the key is that Scintilla does not transform a rectangular selection into multiple stream selections.

    If I recall correctly, this was brought up on the Scintilla list or tracker and they concluded this functionality would not be added to Scintilla. There may be more technical reasons as to why it was not seen as beneficial, however I feel this plugin demonstrates how useful this kind of behavior is.

  • @dail said in Combine 2 files line by line:

    they concluded this functionality would not be added to Scintilla

    Bad news, in a way. In another sense it means that your plug-in will be guaranteed to have a long life.

    Please keep developing it. Thank you.

  • 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.

  • @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

  • 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.

  • @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:


  • @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.

  • @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.

  • 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 :


    REPLACE $0$0

    Best Regards,


  • @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:


    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:


    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.

  • 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!

Log in to reply