Multiline paste with the same number of lines

Hello KDE community,

If we have text like this:

a
b
c

1
2
3

In Sublime Text and Visual Studio Code it is possible to cut three lines with numbers, select lines with letters, do split to multiple lines, use Home to put cursor at line start, make paste and get this:

1a
2b
3c

In Kate 24.08.3 we get this:

1
2
3a
1
2
3b
1
2
3c

I just tried this out in Kate 24.08.3 - if I set up the lines as you have it at the beginning, turn on Block Selection Mode, select the numbers, then position the cursor at the very beginning (in front of the ‘a’), I get the result you’re looking for - perhaps a matter of not pre-selecting all three target lines before pasting?

Hello @johnandmegh,

Thank you for pointing that out, but unfortunately Block Selection Mode is not quite the same as cursors on multiple lines.

With Sublime Text and Visual Studio Code you can transform this:

a
bb
ccc

1
2
3

Into this:

a1
bb2
ccc3

In Kate with Block Selection Mode you will get this:

a1
b2b
c3cc

With cursors on multiple lines you will get this:

a1
2
3
bb1
2
3
ccc1
2
3

Sublime Text produces similar result when number of lines is mismatched. It probably uses special logic when number of lines is the same.

Actually, that example could also be made to work in Kate by putting cursor before the numbers.

Those are just contrived simple examples to demonstrate how multiple cursors work with paste in other popular editors which have similar feature.

Block Selection Mode will not work with irregularly shaped text not at the beginning of the line or when selected lines are not continuous.

Sublime Text was one of the first (if not the first) editors with multiple cursors editing and it had a long time to perfect it. It implements special logic for pasting when there are multiple cursors on the same number of lines. Bonus is that user doesn’t need to think if Block Selection Mode needs to be used for some operations and how. Current conversation proves that point.

Sublime Text doesn’t have separate Block Selection Mode because such feature is simplest use case for multiple cursors and it is not needed. Kate had Block Selection Mode for a very long time before introducing multiple cursors like in Sublime Text, in my humble opinion it should follow that editor with its implementation of similar feature.

In Sublime Text this:

a a
bb bb
ccc ccc

1
2
3

Can be converted to this:

a1 1a
bb2 2bb
ccc3 3ccc

But cursor movement by a word from another recent topic is also needed:

https://discuss.kde.org/t/cursor-movement-by-a-word/26126/1

Better example of what is possible with multi line paste:

https://www.youtube.com/watch?v=fz3wSuCw1zQ

Unless others have suggestions on plugins/other methods to address that particular use case, it sounds like what you’re looking for here would be a good candidate for a wishlist bug report for Kate so devs can assess?

Here is bug report:
https://bugs.kde.org/show_bug.cgi?id=497152

This is possible with multiple cursors. Read the docs about multiple cursors here: Multiple cursors

Block selection can only handle very simple cases and has a totally different usecase.

2 Likes

Kwrite:

multi

Hello waqar,

Thank you for your help. That works.

But what if you want to paste lines from another application?

It is not ideal that you need to paste them in separate location in Kate, convert selection to multiple cursors, make copy and then paste at multiple cursors.

how should one handle that? Kate can’t tell if a copy is multiline or not.

How about checking if number of lines in the clipboard is the same as number of multiple cursors in Kate and making needed transformation internally?

Sublime Text and Visual Studio Code make it work somehow.

If you can reverse engineer that logic, I can implement it.

I strongly believe this is the logic, when pasting to multiple cursors Kate should check if number of lines in the clipboard is the same as multiple cursors and split those lines to corresponding cursor, i.e. each cursor should get single line from the clipboard.

With current implementation in Kate every cursor gets all the lines from the clipboard.

1 Like

Okay thanks. Feel free to file a bug on bugs.kde.org

I will take a look at implementing this, unless you or someone else wants to take a shot at implementing this. Should be a good first issue

1 Like

Here is bug report:
https://bugs.kde.org/show_bug.cgi?id=497863

2 Likes

i just want to say Well Done to all involved

this how things move forward and why KDE is the best desktop for linux.

1 Like

@skyfishgoo thank you for your kind words.

KDE is the best desktop in history of computing. :grinning:

1 Like