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
      last edited by

      When I duplicate when having the selection. e.g. from “a” to 2nd “c” in this case:

      abcdef
      abcdef
      

      I get this:

      abcdef
      abcabcdef
      abcdef
      

      Is it possible to get this? - Duplicate whole lines with selection

      abcdef
      abcdef
      abcdef
      abcdef
      

      I’m not sure, but I think it worked like that in the past or maybe I just remember it from a different program.

      Notepad++ v8.7   (64-bit)
      Build time : Sep 17 2024 - 17:06:31
      Path : C:\Program Files\Notepad++\notepad++.exe
      Command Line : "C:\Program Files\Notepad++\change.log" 
      Admin mode : OFF
      Local Conf mode : OFF
      Cloud Config : C:\DATA\cfg\notepad++
      Periodic Backup : ON
      OS Name : Windows 10 Education (64-bit)
      OS Version : 22H2
      OS Build : 19045.5011
      Current ANSI codepage : 1252
      Plugins : 
          DSpellCheck (1.5)
          HexEditor (0.9.12)
          mimeTools (3.1)
          NppConverter (4.6)
          NppExport (0.4)
          urlPlugin (1.2)
      
      
      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:

        When I duplicate

        That statement is vague.
        What are you doing to “duplicate”?

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

          @Alan-Kilborn Sorry, Ctrl+D, which executes (by default? -not sure if I changed it in the past) SCI_SELECTIONDUPLICATE

          and I want to find something that allows me to press Ctrl+D to duplicate whole lines.

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

            @RARgames said in Duplicate behavior - duplicate whole lines:

            I want to find something that allows me to press Ctrl+D to duplicate whole lines.

            Then give your preferred keyboard shortcut to SCI_LINEDUPLICATE instead – it defaults to nothing, as shown below, but you can assign whatever shortcut you want to it (and remove the shortcut from SCI_SELECTIONDUPLICATE if you don’t ever want to use the fancier “duplicate selection, unless there is no selection in which case duplicate the whole line”)

            6575c033-328d-4cf8-944d-698c69e53978-image.png

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

              SCI_LINEDUPLICATE doesn’t act upon all lines of selected text, only upon the (single) line of the caret.
              Thus the OP’s desire as originally expressed is not satisfied.

              There is no built-in way to achieve: “Duplicate all lines touched by the selection”, AFAIK.
              Well…unless you select the lines in-full and then do SCI_SELECTIONDUPLICATE.
              But if you just want to partially select some lines and have it work on the full lines…then no.

              A workaround, where you start with partially selected line(s):

              • press Tab to indent the lines (lines become fully-selected)
              • press Shift+Tab to dedent the lines (lines are still fully-selected)
              • now do SCI_SELECTIONDUPLICATE
              RARgamesR 1 Reply Last reply Reply Quote 4
              • RARgamesR
                RARgames @PeterJones
                last edited by

                @PeterJones I tried it already, but this always duplicates only 1 line, instead of all lines in selection

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

                  @RARgames ,

                  Sorry, I didn’t notice in your original statement that the selection went across multiple lines.

                  No single Scintilla command will do exactly what you want. But you could record Alan’s sequence as a macro, and assign that macro to a keyboard shortcut.

                  1 Reply Last reply Reply Quote 4
                  • 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