Community
    • Login

    Duplicate behavior - duplicate whole lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    18 Posts 5 Posters 774 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.
    • RARgamesR
      RARgames @Alan Kilborn
      last edited by RARgames

      @Alan-Kilborn Thanks, that’s exactly what I wanted.

      EDIT: Also thanks for the macro suggestion!

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

        The macro is a good suggestion, but there are some caveats:

        • the original selection needs to be a stream selection; if it is a column block selection it will not work
        • the original selection needs to contain a line ending (or more than one); if the selection is only on a single line it will not work
        RARgamesR 1 Reply Last reply Reply Quote 2
        • guy038G
          guy038
          last edited by

          Hello, @rargames, @alan-kilborn, @peterjones and All,

          BTW, did you know these particularities when you invoke the Ctrl + D shortcut …


          Let’s start with this INPUT text :

          This is an
          simple example
          of text to
          see the different
          resulting texts
          when invoking the
          Ctrl-D shortcut
          

          Now, do a normal selection of all this text and use the Ctrl + D shortcut. We get the usual new text , below :

          This is an
          simple example
          of text to
          see the different
          resulting texts
          when invoking the
          Ctrl-D shortcut
          This is an
          simple example
          of text to
          see the different
          resulting texts
          when invoking the
          Ctrl-D shortcut
          

          If, instead of a stream selection, we use a zero-length RECTANGULAR selection, whatever its location, among all allowed ones. Then, after a Ctrl + D operation, we get this text :

          This is an
          This is an
          simple example
          simple example
          of text to
          of text to
          see the different
          see the different
          resulting texts
          resulting texts
          when invoking the
          when invoking the
          Ctrl-D shortcut
          Ctrl-D shortcut
          

          And, if you hit the Ctrl + D shortcut again, every block of two lines is, itself, duplicated. Just as expected !

          However if you do a seven-lines RECTANGULAR selection , at the beginning and, then, hit the End key, now, clicking several times on the Ctrl + D shortcut just add one copy of each line, at a time !


          Of course, if we select a non-zero RECTANGULAR selection of these seven INPUT lines, we get, as expected, all text selected being written twice !

          For instance, let’s do a four chars RECTANGULAR selection, beginning right before the word an of the first line and ending at string hort of the seventh line

          After using the Ctrl + D shortcut, the OUTPUT text becomes :

          This is anan
          simple exampxample
          of text toto
          see the diffdifferent
          resulting teg texts
          when invokinoking the
          Ctrl-D shorthortcut
          

          For the record :

          • If you do a normal selection of one line only, without its like-break, the text of all this line is simply added right after, on the same line

          • If you do a normal selection of one line only, with its line-break, all the text and its like break is duplicated on the line below

          Best Regards,

          guy038

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

            @guy038 said in Duplicate behavior - duplicate whole lines:

            did you know these particularities when you invoke the Ctrl + D shortcut

            I think it might be poor to talk in terms of Ctrl+d, because if memory serves, this shortcut has had some inconsistency (in what command it is tied to) in Notepad++'s history.

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Alan Kilborn
              last edited by

              @Alan-Kilborn ,

              Yes, I think @guy038’s post should be more explicit about “assuming Ctrl+D is mapped to SCI_SELECTIONDUPLICATE (which is the default mapping)”, because this discussion was begun with someone wanting to redefine the Ctrl+D behavior.

              Also, @guy038 said,

              However if you do a seven-lines RECTANGULAR selection , at the beginning and, then, hit the End key, now, clicking several times on the Ctrl + D shortcut just add one copy of each line, at a time !

              … that is only true if Preferences > Editing 2 > ☑ Enable Column Selection to Multi-Editing is checkmarked. If it is not checkmarked, then when you hit END, it leaves column-mode or multi-edit selection mode, and the caret just moves to the end of what used to be the rectangle. (It took me a while to figure this out, because I could replicate all the other behavior mentioned, but I was just not getting the one-copy-of-the-line behavior described.)

              For any such discussion, Preference and Shortcut Mapper states can be quite important to the discussion.

              1 Reply Last reply Reply Quote 2
              • RARgamesR
                RARgames @Alan Kilborn
                last edited by

                @Alan-Kilborn I noticed the 2nd one too - it is quite bad.
                Also, there was a second issue when I started using it, but I don’t remember it right now.

                So I replaced it with slightly different macro:

                • press Ctrl+I to select whole lines, but without last new line char
                • press Shift+Right Arrow to add this new line char (there is an issue if there is no new line[end of the file] - same with previous macro)
                • press Ctrl+D to duplicate
                • press `Home to return to the line start (I don’t like this - it would be better to return to a previous cursor placement)

                It works better for me, but still has some issues.

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

                  @RARgames said in Duplicate behavior - duplicate whole lines:

                  press Ctrl+I to select whole lines, but without last new line char

                  By default Ctrl+i is assigned to the Split Lines command, and I don’t see how that is helpful here??

                  PeterJonesP 1 Reply Last reply Reply Quote 0
                  • PeterJonesP
                    PeterJones @Alan Kilborn
                    last edited by PeterJones

                    @Alan-Kilborn ,

                    I believe @RARgames is relying on a side effect: if your caret is on a line that’s shorter than the screen-width (or than the first vertical edge setting), then Ctrl+I’s “Split Lines” actions will select the whole line, split it into one line, and finish with the whole line is suggested.

                    If @RARgames had instead tried on a line that goes beyond the first vertical edge setting or screen width, the Ctrl+I would have actually split the lines into 2 or more lines, and ended with all N of those lines selected. To continue with that modified macro invites the danger of accidentally splitting long lines in the future.

                    Further, doing the Ctrl+I first would only do anything for @RARgames if there was a stream selection that went from the middle of one line to the middle of some other line (or from the beginning of one line to the end of another without selecting the EOL sequence).

                    @RARgames said,

                    it would be better to return to a previous cursor placement

                    Macros don’t have variables/memory, so they have no place to track such a thing. As our Notepad++ Automation FAQ says, if you need something with “memory”, you need to switch from Macros to a true programming language, like one of the scripting plugins (PythonScript Plugin being the most-frequently mentioned, here). With a scripting plugin, you could put the full logic: "look at the active stream selection; if the start of the selection is not at the start of the line, move it to the start of the line; if the end of the selection is not after the EOL sequence (or not at EOF if the end of the last line doesn’t have EOL)

                    RARgamesR 1 Reply Last reply Reply Quote 4
                    • RARgamesR
                      RARgames @PeterJones
                      last edited by

                      @PeterJones Thanks, I’ll probably do that when I have some free time. For now, I’ll stick to the combination of my macro/SCI_SELECTIONDUPLICATE as it is good enough.

                      1 Reply Last reply Reply Quote 0
                      • NicholasN
                        Nicholas
                        last edited by

                        If you click and drag on the line numbers it will select the whole line. I always use this method when selecting lines I want to duplicate or copy.

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

                          @Nicholas

                          Yes, but that’s probably not relevant to the OP’s situation.

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