Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 4e9edef5cef4c50001000007

PHP Array Syntax -> MailChimp Merge Syntax

I recently needed to send an e-mail to our marketing department listing allowed merge tags for our MailChimp campaigns. The allowed merge tags were determined from a PHP array in one of our PHP classes. I transformed the PHP class to MailChimp's syntax and sent the e-mail. It was, however, a long, laborious process. I'm still fairly new to Vim and would love to see how an expert Vim user would tackle one of my own, real-world problems. Thanks and have fun!

Start file
$allowed = array("PIN", "Prefix", "LastName", "FirstName", "MiddleName", 
  "Address1", "Address2", "City", "State", "Zip", "Country", "phone", "mobile",
  "Email", "MothersMaiden", "security1_id", "security1_answer", 
  "security2_id", "security2_answer", "BirthDate", 
  "flag1", "DriversLicense", "gender");
End file
*|PIN|*
*|Prefix|*
*|LastName|*
*|FirstName|*
*|MiddleName|*
*|Address1|*
*|Address2|*
*|City|*
*|State|*
*|Zip|*
*|Country|*
*|phone|*
*|mobile|*
*|Email|*
*|MothersMaiden|*
*|security1_id|*
*|security1_answer|*
*|security2_id|*
*|security2_answer|*
*|BirthDate|*
*|flag1|*
*|DriversLicense|*
*|gender|*

View Diff

1,5c1,23
< $allowed = array("PIN", "Prefix", "LastName", "FirstName", "MiddleName", 
<   "Address1", "Address2", "City", "State", "Zip", "Country", "phone", "mobile",
<   "Email", "MothersMaiden", "security1_id", "security1_answer", 
<   "security2_id", "security2_answer", "BirthDate", 
<   "flag1", "DriversLicense", "gender");
---
> *|PIN|*
> *|Prefix|*
> *|LastName|*
> *|FirstName|*
> *|MiddleName|*
> *|Address1|*
> *|Address2|*
> *|City|*
> *|State|*
> *|Zip|*
> *|Country|*
> *|phone|*
> *|mobile|*
> *|Email|*
> *|MothersMaiden|*
> *|security1_id|*
> *|security1_answer|*
> *|security2_id|*
> *|security2_answer|*
> *|BirthDate|*
> *|flag1|*
> *|DriversLicense|*
> *|gender|*

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 103 remaining solutions by signing in and submitting your own entry
#104 Salleyron Julien / juguul - Score: 45 - 01/11/14 @ 21:51
df(:%s/"\(\w\+\)",\?\s*\n*\s*/*|\1|*\r/g<CR>ddZZ

0 comments


#105 Justin Knag / justinknag - Score: 45 - 08/28/14 @ 17:17
dt"5Jf)C, <C-C><C-C>:%s/", /|*\r/g<CR>dd:<Up><Left><Left><BS><BS><BS><Left>*<Left><Left><BS><BS><CR>ZZ

0 comments


#106 James Cash / jamesnvc - Score: 46 - 10/19/11 @ 14:46
:%s/",/|*<C-V><CR>/g<CR>f"C|*<Esc>:%s/^.*"/*|/<CR>:g/^\s*$/d<CR>ZZ

0 comments


#107 Chaiporn Jaikaeo / cjaikaeo - Score: 49 - 11/27/11 @ 17:37
:%s/[^"]*"\([^"]*\)"[^"]*/*|\1|*<C-V><CR>/g<CR>:g/^ *$/d<CR>ZZ

0 comments


#108 Iori ONDA / 120reset - Score: 50 - 12/14/11 @ 11:14
df(:%s/ *"\([^"]*\)"[,);]*/*|\1|*\r/g<CR>:g/^ *$/d<CR>ZZ

0 comments


#109 Angela Harms / angelaharms - Score: 50 - 01/18/12 @ 00:52
df"5J:s/", "/<C-V><CR>/g<CR>f"D:%s/\()<BS>/<BS>.*\(<BS>)/*|\1|*/<CR>:wq<CR>

0 comments


#110 Daniel Schierbeck / dasch - Score: 51 - 12/06/11 @ 16:30
d4w:%s/, "/\r/g<CR>:%s/W<BS>\W//g<CR>:%s/\w\<Left><Right>+/*|\0|*/<CR>:wq<CR>

0 comments


#111 Tom Fetherston / TomFetherston - Score: 51 - 01/18/12 @ 04:47
jyi(:%d<NL>"0p5J:%s/,/\r/g<NL>:%s/^ *"/*|/g<NL>:%s/"/|*/g<NL>ZZ

TomFetherston: j # down to put cursor inside paren's yi( # yank text inside the parens :%d<NL> #empty the buffer "0p #paste from the 'yank-storing-register', i.e. 0 5J #join five lines into one :%s/,/\r/g #replace all commas with a return (eol in effect) :%s/^ *"/*|/g #replace the opening quote, (including leading spaces) with '*|' :%s/"/|*/g #replace the closing quote with '|*' ZZ #'save&quit'

1 comment


#112 Roman Mašek / romario333 - Score: 52 - 10/24/11 @ 21:06
df(:%s/ *"\([^"]*\)"[,);]*/*|\1|*\r/g<CR>:g/^ *$/d<CR>:wq<CR>

0 comments


#113 Gowtham Madhava / gowthamgowtham - Score: 52 - 11/02/11 @ 17:34
df(5Jf)d$:%s<BS><BS>s/.<BS>, /<C-V><CR>/g<CR>:%s/^"/*|/g<CR>:%s/"$/|*/g<CR>ZZ

0 comments


#114 Ethan / ethanmiller - Score: 52 - 01/31/12 @ 04:17
:%s/"\([^"]\+\)"[^"]\+/\r*|\1|*/g<CR>/^ <CR>ddn.n.n.ggddZZ

0 comments


#115 Scott Schlesier / sschlesier - Score: 52 - 02/22/12 @ 06:29
jdi(dd"2p:%s/\n//g<CR>A,<Esc>:s/", */|*\r/g<CR>dd:%s/"/*|/g<CR>ZZ

0 comments


#116 無ん垢の叫び / john_ababa - Score: 52 - 02/28/12 @ 16:04
:%s/",/|*<C-V><CR>/g|%s/ "/*|/g<CR><CR>f"C|*<Esc>ggcf"*|<Esc>=G:g/^$/d<CR>ZZ

0 comments


#117 Antoni Villalonga / friki - Score: 52 - 08/15/16 @ 18:33
:%s_",_|*\r_g<CR>A<BS><BS><BS>|*<Esc>:%s_.*"_*|_<CR>3<Up>dd4<Up>dd5<Up>dd5G<Down>ddZZ

0 comments


#118 415fox / 415fox - Score: 53 - 11/08/11 @ 18:10
5J:%<BS><BS>0qadt<Esc>df"i*|<Esc>f"cw|*<Esc>lq50@a:s/\*\*/\*<C-V><CR>\*/g<CR>:wq<CR>

0 comments


#119 Mattiassich Ákos / mattiassicha - Score: 53 - 11/23/11 @ 20:31
jdi(dd"2p:%s/",\s*/|*\r/g<CR>:v/\S/d<CR>:%s/ *"/*|/<CR>A<BS>|*<Esc>ZZ

0 comments


#120 Martin Liberg / marreman - Score: 53 - 02/07/15 @ 19:06
f"yi(5dd"0p:%s/,\_s*/\r/g<CR>:%s/"\([^"]*\)"/*|\1|*/g<CR>ZZ

0 comments


#121 Michael / patheticpat - Score: 54 - 12/17/12 @ 15:09
dt":%s/",/|*/g|%s/"/*|/g<CR><CR>:%s/ /\r/g<CR>:g/^$/d<CR>G$xxhxpZZ

0 comments


#122 flembo's dad / Lspacewalker - Score: 55 - 12/27/11 @ 19:51
jdi($pd0:%s/\"\(\w\+\)\"\,\?\s*\n*\s*/\*|\1|\*\r/g<NL>ddZZ

0 comments


#123 D A / 7187dd578b325d2 - Score: 57 - 11/24/11 @ 12:25
:%s/\v"(.{-})"/*|\1|*/g<CR>:%s/,/\r/g<CR>:%le<CR>$xx{J{J{J{J{df(ZZ

0 comments


#124 Bruce Woodward / Bruce_Woodward - Score: 60 - 10/24/11 @ 10:57
5J:s/.*(\|);\|\r//g|s/", /\|*\r/g|%s/^"/*\|/g|s/"/\|*/<CR><CR>:wq<CR>

0 comments


#125 Jouko Karvonen / joukokar - Score: 62 - 10/22/11 @ 06:42
df(:%s/,/\r/g<CR>:%s/[ "]//g<CR>:g/^$/d<CR>G$xx:%s/^/*|/<CR>:%s/$/|*/<CR>:wq<CR>

0 comments


#126 Aviv Ben-Yosef / avivby - Score: 63 - 10/20/11 @ 17:34
df(:%s/ //g<CR>:%s/,/\r/g<CR>:g/^$/d<CR>jj$xxggqqcw*|<C-C><C-C>A<BS>|*<C-C><C-C>j0q@q30@@ZZ

0 comments


#127 celery rho gamma / rentalcustard - Score: 66 - 10/19/11 @ 15:07
:%s/"\(\w*\)",\?/*|\1|*\r/g<CR>:%S/<BS><BS>s/^ *//g<CR>dd3k.4k.5k.6G.ggdf(:wq<CR>

0 comments


#128 James Freed / JamesTFreed - Score: 66 - 02/02/12 @ 23:26
jyi(:%d<CR>pu"0p5J:%s/, /\r/g<CR>:s/^"/*|/g<CR>u<Up>:<Up><Left><Left><Left><Left><Left><Left><Left><Left><Left><Right><Left>%<CR>:%s/"/|*<CR>ZZ

0 comments


#129 Zee Spencer / zspencer - Score: 168 - 01/18/12 @ 00:51
f(d0:s/\n<BS><BS>, /\n<CR>u<Up><Up><Up><Up>:<Up><Left><Left> <CR>u:<Up><Left><Left><BS><Right><Right>\<BS>/g<CR>u:<Up><Left><Left><Right><Right><Left><Left><Left><Left><Left><Left><Left><Left><Left>%<Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><CR>u<Up>:<Up><Left><Left><Left><Right>\r<Left><Left><CR>u<Up>:<Up><Left><Left><Left><Left><BS><BS><CR>ggx:%s/\r\r/\r/g<CR>:6d<CR>d0%<Esc>:%s/  //g<CR><BS><Down>i<BS><Esc>:18<CR>dd:%s/"<BS>^"/*|/g<CR>:%s/".*/|*/g<CR>ZZ

0 comments


Created by: meekish

129 active golfers, 407 entries

Leaderboard (lowest score wins):
23
#1 - h_east (トロッコ6個) / h_east

10/20/2011 at 12:36AM

23
#2 - You-Siang Lin / yslinnctu

11/28/2011 at 02:07AM

23
#3 - Balkoth / _Balkoth_

12/03/2011 at 09:50PM

23
#4 - no / jt_vg

12/14/2011 at 06:10PM

23
#5 - Mihai Crăiță / mihai_craita

12/18/2011 at 12:20PM

23
#6 - Federico Galassi / federicogalassi

12/18/2011 at 09:58PM

23
#7 - Pei-Lun Lee / ypcatw

12/21/2011 at 04:57AM

23
#8 - Justin Love / wondible

12/24/2011 at 04:07PM

23
#9 - veki / vx_ras

02/02/2012 at 10:59PM

23
#10 - Abdel Said / abdelsaid

02/10/2012 at 11:53PM

23
#11 - Renat Aksitov / Korvin79

03/01/2012 at 07:26AM

23
#12 - Sebastian Kusnier / skusnier

05/05/2012 at 07:41PM

23
#13 - Rod Knowlton / codelahoma

05/08/2012 at 01:28AM

23
#14 - Tim Chase / gumnos

05/28/2012 at 12:36AM

23
#15 - (Emile (Swarts)) / EmileSwarts

08/19/2012 at 06:37PM

23
#16 - Conner McDaniel / connermcd

09/18/2012 at 05:53AM

23
#17 - Petro Тrouq / zulolosi

08/22/2013 at 06:07PM

23
#18 - Charles H. Leggett / cleggett

11/05/2013 at 04:58PM

23
#19 - John Braxler / braxler

05/01/2014 at 02:26PM

23
#20 - LC / leeren

08/10/2014 at 07:29AM

23
#21 - Jon Krause / jkrause314

01/27/2016 at 11:02PM

23
#22 - Turkey Man / lvturkeyman

11/27/2017 at 04:42PM

23
#23 - Evgeny`s Kindle / EvgenyKindle

05/02/2018 at 07:10AM

24
#24 - vimja / vimja666

10/29/2011 at 07:17AM

24
#25 - A / tndrnt

12/10/2011 at 02:20PM

24
#26 - Vasil Sakarov / vsakarov

12/28/2011 at 10:06AM

24
#27 - Xavier Nayrac / lkdjiin

01/02/2012 at 04:50PM

24
#28 - Grigoriy Glushko / grinderrz

02/17/2012 at 09:52AM

24
#29 - ise0615 / ise0615

05/05/2012 at 10:52AM

24
#30 - Kerson Hsiao / KersonHsiao

07/03/2012 at 03:45PM