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

0 comments

#102 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

#103 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

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

0 comments

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

0 comments

#106 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

#107 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

#108 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

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

0 comments

#110 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

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

0 comments

#112 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

#113 無ん垢の叫び / 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

#114 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

#115 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

#116 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

#117 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

#118 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

#119 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

#120 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

#121 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

#122 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

#123 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

#124 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

#125 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

#126 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

126 active golfers, 390 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 - Leeren / Leeren

08/10/2014 at 07:29AM

23
#21 - Jon Krause / jkrause314

01/27/2016 at 11:02PM

24
#22 - vimja / vimja666

10/29/2011 at 07:17AM

24
#23 - A / tndrnt

12/10/2011 at 02:20PM

24
#24 - Vasil Sakarov / vsakarov

12/28/2011 at 10:06AM

24
#25 - Xavier Nayrac / lkdjiin

01/02/2012 at 04:50PM

24
#26 - Grigoriy Glushko / grinderrz

02/17/2012 at 09:52AM

24
#27 - ise0615 / ise0615

05/05/2012 at 10:52AM

24
#28 - Kerson Hsiao / KersonHsiao

07/03/2012 at 03:45PM

24
#29 - Urtica dioica / udioica

12/12/2012 at 05:40AM

24
#30 - Trevor Powell / DoomedBunnies

03/20/2013 at 03:39AM

24
#31 - Marco Hinz / _mhinz_

05/23/2013 at 11:04AM

24
#32 - Joonas Pihlajamaa / jokkebk

02/23/2014 at 12:27PM

24
#33 - pftb12345 / pftb12345

04/14/2015 at 11:06AM

25
#34 - Sergey Panin / dixPro

11/08/2011 at 02:48PM

25
#35 - Dragan Cvetinovic / kawkafi

11/20/2011 at 02:53PM

25
#36 - Gabriel Barta / gbarta

12/02/2011 at 01:17PM

25
#37 - 0x5042 / 0x5042

12/09/2011 at 10:00PM

25
#38 - Jaime A. Sánchez / jashbeta

12/23/2011 at 02:14AM

25
#39 - John Anderson / opejn

12/24/2011 at 05:22AM

25
#40 - Bradd Szonye / bszonye

07/15/2013 at 03:53AM

25
#41 - Quota / Quotad

02/25/2014 at 08:43AM

26
#42 - oliver mueller / marcontwit

01/19/2012 at 09:36AM

27
#43 - Daniel Lundin / danielundin

11/27/2011 at 08:56PM

27
#44 - Al / 96258

12/13/2011 at 12:52PM

27
#45 - peter reisinger / PeterReisinger

12/30/2011 at 05:54PM

27
#46 - Woojung Kim 김우중 / _kimwz

07/16/2013 at 02:43AM

27
#47 - Oliver Christ / 0liverChrist

10/11/2013 at 09:23PM

27
#48 - Matt Robbins / mcrmfc

11/24/2014 at 04:13PM

27
#49 - Mauro Persano / fzort

05/25/2015 at 01:25AM

28
#50 - Alex David / alexd_me

03/27/2012 at 06:01PM

28
#51 - Mauro Persano / fzort

11/22/2014 at 03:42PM

29
#52 - Jose Gutierrez / Jogusa

09/20/2014 at 07:01PM

29
#53 - Daniel / Daniel00288663

04/04/2017 at 09:34AM

30
#54 - Federico Bond / federicobond

07/18/2012 at 06:13AM

30
#55 - Marcin Sza / coot_

11/28/2012 at 08:16PM

30
#56 - Gurukandhamoorthi / Gurukandhamoor1

08/04/2017 at 06:05PM

31
#57 - brett / brettyukich

09/22/2013 at 08:52PM

31
#58 - w1zeman1p / wizemanip

11/18/2014 at 05:17PM

32
#59 - Scott Wehrenberg / swehren

05/18/2012 at 02:35PM

32
#60 - RobertT / techrt2050

07/16/2013 at 05:24AM

32
#61 - cj / cj01101

08/20/2013 at 10:09PM

32
#62 - James / Dronak

09/21/2014 at 02:05AM

33
#63 - Jer Wilson / superjercom

10/28/2011 at 07:00AM

33
#64 - Pavlo Klets / p01nt

10/28/2011 at 09:12AM

33
#65 - Daniel Hjerth / danielhjerth

11/09/2011 at 06:02PM

33
#66 - Conrad Indiono / indygemma

12/12/2011 at 10:48AM

33
#67 - Peter Anselmo / peter_anselmo

03/02/2012 at 06:02PM

33
#68 - .さとうにるぽ引退.swp / nillpo

01/08/2015 at 02:26AM

33
#69 - TheProgrammer971 / tp971

03/14/2015 at 02:39AM

34
#70 - Neal Lindsay / neall

11/12/2011 at 05:50PM

34
#71 - Matt Woelk / MattWoelk

11/13/2011 at 04:30AM

34
#72 - not so punk :] / notsopunk

03/31/2012 at 07:48AM

34
#73 - Dave@Highgroove / HighgrooveDave

05/23/2012 at 03:07AM

34
#74 - Tyler / tylerbindon

04/03/2013 at 08:28PM

34
#75 - Xelrifos / Xelrifos

02/23/2014 at 12:38PM

35
#76 - Camac / gregorbyte

12/12/2011 at 06:21AM

35
#77 - sebtyp / sebtyp

12/15/2011 at 07:41PM

35
#78 - Dj Vimgolf / dj_vimgolf

12/31/2011 at 02:30AM

36
#79 - Nolen Royalty / NolenRoyalty

04/21/2012 at 03:41AM

37
#80 - Travis Jeffery / travisjeffery

12/02/2011 at 11:15PM

37
#81 - Jonathan Lozinski / jlozinski

04/21/2012 at 04:59PM

38
#82 - Mislav Marohnić / mislav

12/05/2011 at 03:18PM

38
#83 - Stephen Crosby / stevecrozz

12/20/2011 at 09:53PM

38
#84 - Ben Friedland / bfriedland174

05/22/2012 at 03:59AM

39
#85 - Joel Bradshaw / cincodenada

11/23/2011 at 10:23PM

39
#86 - learninghang / learninghang

04/14/2012 at 07:52AM

40
#87 - Ernestas / ernestas

10/19/2011 at 04:15PM

40
#88 - Joe Nerdan / JoeNerdan

12/15/2011 at 08:09PM

40
#89 - naught101 / naught101

03/14/2012 at 04:00AM

41
#90 - Panino Matic / paninomatik

10/27/2011 at 05:33AM

41
#91 - Michael Norton / DocOnDev

01/18/2012 at 12:50AM

42
#92 - Vitor Eiji / vitoreiji0

10/21/2011 at 01:56PM

43
#93 - RusAlex Pletnev / RusAlexander

11/14/2011 at 06:22PM

43
#94 - Jacob Vosmaer / jacobvosmaer

06/03/2012 at 02:41PM

43
#95 - utopiah / utopiah

06/09/2012 at 08:49AM

44
#96 - Raphaël De Giusti / raphdg

10/26/2011 at 07:28AM

44
#97 - Sergi Sorribas / lerovitch

12/22/2011 at 04:19PM

44
#98 - Tara Bass / tara_bass

12/23/2011 at 06:25AM

45
#99 - Jed Hurt / meekish

10/19/2011 at 03:00PM

45
#100 - Mark Reed / markjreed

10/22/2011 at 10:44PM

45
#101 - Salleyron Julien / juguul

01/11/2014 at 09:51PM

45
#102 - Justin Knag / justinknag

08/28/2014 at 05:17PM

46
#103 - James Cash / jamesnvc

10/19/2011 at 02:46PM

49
#104 - Chaiporn Jaikaeo / cjaikaeo

11/27/2011 at 05:37PM

50
#105 - Iori ONDA / 120reset

12/14/2011 at 11:14AM

50
#106 - Angela Harms / angelaharms

01/18/2012 at 12:52AM

51
#107 - Daniel Schierbeck / dasch

12/06/2011 at 04:30PM

51
#108 - Tom Fetherston / TomFetherston

01/18/2012 at 04:47AM

52
#109 - Roman Mašek / romario333

10/24/2011 at 09:06PM

52
#110 - Gowtham Madhava / gowthamgowtham

11/02/2011 at 05:34PM

52
#111 - Ethan / ethanmiller

01/31/2012 at 04:17AM

52
#112 - Scott Schlesier / sschlesier

02/22/2012 at 06:29AM

52
#113 - 無ん垢の叫び / john_ababa

02/28/2012 at 04:04PM

52
#114 - Antoni Villalonga / friki

08/15/2016 at 06:33PM

53
#115 - 415fox / 415fox

11/08/2011 at 06:10PM

53
#116 - Mattiassich Ákos / mattiassicha

11/23/2011 at 08:31PM

53
#117 - Martin Liberg / marreman

02/07/2015 at 07:06PM

54
#118 - Michael / patheticpat

12/17/2012 at 03:09PM

55
#119 - flembo's dad / Lspacewalker

12/27/2011 at 07:51PM

57
#120 - D A / 7187dd578b325d2

11/24/2011 at 12:25PM

60
#121 - Bruce Woodward / Bruce_Woodward

10/24/2011 at 10:57AM

62
#122 - Jouko Karvonen / joukokar

10/22/2011 at 06:42AM

63
#123 - Aviv Ben-Yosef / avivby

10/20/2011 at 05:34PM

66
#124 - celery rho gamma / rentalcustard

10/19/2011 at 03:07PM

66
#125 - James Freed / JamesTFreed

02/02/2012 at 11:26PM

168
#126 - Zee Spencer / zspencer

01/18/2012 at 12:51AM