• Login
Community
  • Login

Duplicate behavior - duplicate whole lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
18 Posts 5 Posters 818 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.
  • A
    Alan Kilborn @RARgames
    last edited by Oct 22, 2024, 12:35 PM

    @RARgames said in Duplicate behavior - duplicate whole lines:

    When I duplicate

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

    R 1 Reply Last reply Oct 22, 2024, 12:43 PM Reply Quote 1
    • R
      RARgames @Alan Kilborn
      last edited by RARgames Oct 22, 2024, 12:44 PM Oct 22, 2024, 12:43 PM

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

      P 1 Reply Last reply Oct 22, 2024, 1:17 PM Reply Quote 0
      • P
        PeterJones @RARgames
        last edited by PeterJones Oct 22, 2024, 1:20 PM Oct 22, 2024, 1:17 PM

        @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

        R 1 Reply Last reply Oct 22, 2024, 1:22 PM Reply Quote 3
        • A
          Alan Kilborn
          last edited by Alan Kilborn Oct 22, 2024, 1:26 PM Oct 22, 2024, 1:21 PM

          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
          R 1 Reply Last reply Oct 22, 2024, 5:21 PM Reply Quote 4
          • R
            RARgames @PeterJones
            last edited by Oct 22, 2024, 1:22 PM

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

            P 1 Reply Last reply Oct 22, 2024, 1:34 PM Reply Quote 0
            • P
              PeterJones @RARgames
              last edited by Oct 22, 2024, 1:34 PM

              @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
              • R
                RARgames @Alan Kilborn
                last edited by RARgames Oct 22, 2024, 5:23 PM Oct 22, 2024, 5:21 PM

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

                EDIT: Also thanks for the macro suggestion!

                1 Reply Last reply Reply Quote 1
                • A
                  Alan Kilborn
                  last edited by Oct 23, 2024, 11:24 AM

                  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
                  R 1 Reply Last reply Oct 24, 2024, 12:38 PM Reply Quote 2
                  • G
                    guy038
                    last edited by Oct 23, 2024, 12:37 PM

                    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

                    A 1 Reply Last reply Oct 23, 2024, 3:16 PM Reply Quote 1
                    • A
                      Alan Kilborn @guy038
                      last edited by Alan Kilborn Oct 23, 2024, 3:16 PM Oct 23, 2024, 3:16 PM

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

                      P 1 Reply Last reply Oct 23, 2024, 3:58 PM Reply Quote 0
                      • P
                        PeterJones @Alan Kilborn
                        last edited by Oct 23, 2024, 3:58 PM

                        @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
                        • R
                          RARgames @Alan Kilborn
                          last edited by Oct 24, 2024, 12:38 PM

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

                          A 1 Reply Last reply Oct 24, 2024, 3:25 PM Reply Quote 0
                          • A
                            Alan Kilborn @RARgames
                            last edited by Oct 24, 2024, 3:25 PM

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

                            P 1 Reply Last reply Oct 24, 2024, 4:49 PM Reply Quote 0
                            • P
                              PeterJones @Alan Kilborn
                              last edited by PeterJones Oct 24, 2024, 9:31 PM Oct 24, 2024, 4:49 PM

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

                              R 1 Reply Last reply Oct 26, 2024, 2:06 PM Reply Quote 4
                              • R
                                RARgames @PeterJones
                                last edited by Oct 26, 2024, 2:06 PM

                                @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
                                • N
                                  Nicholas
                                  last edited by Oct 27, 2024, 12:12 AM

                                  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.

                                  A 1 Reply Last reply Oct 27, 2024, 10:38 AM Reply Quote 0
                                  • A
                                    Alan Kilborn @Nicholas
                                    last edited by Oct 27, 2024, 10:38 AM

                                    @Nicholas

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

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