Extract values from associative array (or to put it simply: from second column) and some multiple selections issue

Hello to everyone.
I’ve only been using Kakoune for 1 full day.
I code in php and quite often it is necessary to convert the associative array into an array with values.

Fake example :slight_smile:
array(
‘form’ => $form->createView(),
‘publication’ => $npwPublication,
‘pressForm’ => $pressForm->createView(),
)

Result should be
array(
$form->createView(),
$npwPublication,
$pressForm->createView(),
)

So i jumped to first line, gi to first char (because code is indented),
grab 3 lines with shift+x,
then split selection into lines with alt+s,
then select from end to dollar sign with alt+f and $ as my wanted stop character.
And finally, y to copy :slight_smile:

Is there an easier way to select this?

But what I have the biggest problem with is how to move the copied lines to another place.

When I move the cursor down I have 3 of them and when I align the first one in final place in file, the other 2 are overlap another code so I cannot paste selection content without mixing with the rest. :frowning:

So I figured I’d reduce the selection (with space) to one and it would be much easier for me to hit my target line. But when I do that, the paste command only returns 1 line out of the 3 I copied.

I tried to copy these lines to another buffer, but the effect is the same.

Can you suggest something?

Thanks in advance and have a nice day :slightly_smiling_face:

You could also use 2C to directly create 3 selection. And then f$<a-l>y for the yanking

So when you yank with 3 cursors, you have 1 yank per cursor, therefore you also need 3 cursor to paste all 3 selections.

I don’t know if it’s the fastest, but what I would do ( after yanking the 3 lines ):
press <space> to go back to 1 cursor
move to the place I want to paste
create 3 empty line with 3<a-o>
go down with j and create 3 cursors with 2C
paste with p

now regarding if you yanked the \n newline character you might have an extra newline. Just press d to delete it.

1 Like

I think the solution to your issue is <a-p>/<a-P>:

<a-p>
    paste all after the end of each selection, and select each pasted string

<a-P>
    paste all before the start of each selection, and select each pasted string

Note that unless your selections contain end-of-line (in your case I think they do) you’d have to append a newline a<ret><esc> after pasting if you want your selections to be in different lines.

2 Likes

Thank you both for the answers.
I found the solution a few hours after writing the post, just before bedtime.

As @bravekarma writes, the solution is alt+p / alt+P.
I must have skipped it when I read for a first time https://kakoune.org/why-kakoune/why-kakoune.html, a few days ago.

But I learned something new anyway, thanks to @scr.
Copying the selection to a new line is great.

But when I paste (alt+p) this selection all lines are merged into 1, which is not a big problem as I can break them again using a comma :slight_smile:

$form->createView(),$npwPublication,$pressForm->createView(),

Such a a great editor.
While PhpStorm is a great IDE, without the plugins, the text editing was poor.

Thanks again and have a nice day.

Yes it worth it to go through :doc keys from time to time. I have been using kakoune since a while now but I still discover new stuff ! it is a great editor :heart_eyes: