I like the solution of AlexRus (I love Vim macros).
But I think a more realistic situation would be to insert key / value pairs from another application / document:
betty bravo cindy charlie deana delta
and perform a sequence of conversions on each line.
SOLUTION 1
We could select all three lines using <Sv>jj or some other way and apply a series of search / replace in the selection:
:'<,'>s/^/$mynames[' gv to reselect :'<,'>s/ /'] = ' gv to reselect :'<,'>s/$/';
The whole editing sequence looks like this:
<Sv>jj:s/^/$mynames['<CR>gv:s/ /'] = '<CR>gv:s/$/';<CR>
SOLUTION 2
We could apply one search / replace
:'<,'>s/^\(.*\) \(.*\)$/$myname['\1'] = '\2';
where the search part isolates the beginning of the line ( ^ ), the space between words ( ) and the end of the line ( $ ), actually matching the text between them and the replacement part, replaces the entire line with $myname[' + first match ( \1 ) + '] = ' + second match ( \2 ) + '; .
I'm not good at regex, so I had to check my notes to put them together, but I have no doubt that many Vim users can type this command at a time. I will ever be.
The whole editing sequence looks like this:
<Sv>jj:s/^\(.*\) \(.*\)$/$myname['\1'] = '\2';<CR>
SOLUTION 3
With the same setup, we could enter VISUAL-BLOCK mode at the beginning of the first line using <Cv> , skip as far as possible and type I$myaccess['<Esc> to get:
$mynames['betty bravo $mynames['cindy charlie $mynames['deana delta
move the cursor to the space between words with f<Space> , press <Cv> again, expand the selection below and type c'] = '<Esc> to get:
$mynames['betty'] = 'bravo $mynames['cindy'] = 'charlie $mynames['deana'] = 'delta
then move to the end of the line with $ , press <Cv> again, select what you want again, and enter A';<Esc> for the last touch.
The whole editing sequence looks like this:
<Cv>jjI$myaccess['<Esc>f <Cv>jjc'] = '<Esc>$<Cv>jjA';<Esc>