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

**URL:** <https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181>\
**Category:** Help\
**Created:** [August 1, 2020, 2:57pm UTC](https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181 "2020-08-01T14:57:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackStarborn](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@JackStarborn](https://discuss.kakoune.com/u/JackStarborn)\
**Post date:** [August 1, 2020, 2:57pm UTC](https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181/1 "2020-08-01T14:57:11Z")

</div>

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 🙂  
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 🙂

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

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 🙂

---

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [August 1, 2020, 4:44pm UTC](https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181/2 "2020-08-01T16:44:15Z")

</div>

> [@JackStarborn](#):
>
> 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,

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.

---

<div class="post-metadata">

**Author:** ![bravekarma](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@bravekarma](https://discuss.kakoune.com/u/bravekarma)\
**Post date:** [August 1, 2020, 5:29pm UTC](https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181/3 "2020-08-01T17:29:24Z")

</div>

> [@JackStarborn](#):
>
> 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 think the solution to your issue is `<a-p>`/`<a-P>`:

```auto
<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.

---

<div class="post-metadata">

**Author:** ![JackStarborn](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@JackStarborn](https://discuss.kakoune.com/u/JackStarborn)\
**Post date:** [August 2, 2020, 1:14pm UTC](https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181/4 "2020-08-02T13:14:44Z")

</div>

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](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 🙂

```
$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.

---

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [August 2, 2020, 1:30pm UTC](https://discuss.kakoune.com/t/extract-values-from-associative-array-or-to-put-it-simply-from-second-column-and-some-multiple-selections-issue/1181/5 "2020-08-02T13:30:20Z")

</div>

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 😍
