Duplicate behavior - duplicate whole lines
-
@RARgames said in Duplicate behavior - duplicate whole lines:
When I duplicate
That statement is vague.
What are you doing to “duplicate”? -
@Alan-Kilborn Sorry,
Ctrl+D
, which executes (by default? -not sure if I changed it in the past) SCI_SELECTIONDUPLICATEand I want to find something that allows me to press
Ctrl+D
to duplicate whole lines. -
@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”)
-
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 doSCI_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
-
@PeterJones I tried it already, but this always duplicates only 1 line, instead of all lines in selection
-
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.
-
@Alan-Kilborn Thanks, that’s exactly what I wanted.
EDIT: Also thanks for the macro suggestion!
-
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
-
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 theCtrl + 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 stringhort
of the seventh lineAfter 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
-
-
@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.
-
Yes, I think @guy038’s post should be more explicit about “assuming
Ctrl+D
is mapped toSCI_SELECTIONDUPLICATE
(which is the default mapping)”, because this discussion was begun with someone wanting to redefine theCtrl+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 theCtrl + 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.