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 530d2148f78def0002660c96

Write Setters and Getters for PHP

Just simple automation of writing Setters and Getters like Doctrine might use.

Start file
<?php
class Example {

	firstProperty
	secondItem
	lastAttribute
}
End file
<?php
class Example {

	private $firstProperty;

	public function getFirstProperty()
	{
		return $this->firstProperty;
	}

	public function setFirstProperty($value)
	{
		$this->firstProperty = $value;
	}

	private $secondItem;

	public function getSecondItem()
	{
		return $this->secondItem;
	}

	public function setSecondItem($value)
	{
		$this->secondItem = $value;
	}

	private $lastAttribute;

	public function getLastAttribute()
	{
		return $this->lastAttribute;
	}

	public function setLastAttribute($value)
	{
		$this->lastAttribute = $value;
	}
}

View Diff

4,6c4,38
< 	firstProperty
< 	secondItem
< 	lastAttribute
---
> 	private $firstProperty;
> 
> 	public function getFirstProperty()
> 	{
> 		return $this->firstProperty;
> 	}
> 
> 	public function setFirstProperty($value)
> 	{
> 		$this->firstProperty = $value;
> 	}
> 
> 	private $secondItem;
> 
> 	public function getSecondItem()
> 	{
> 		return $this->secondItem;
> 	}
> 
> 	public function setSecondItem($value)
> 	{
> 		$this->secondItem = $value;
> 	}
> 
> 	private $lastAttribute;
> 
> 	public function getLastAttribute()
> 	{
> 		return $this->lastAttribute;
> 	}
> 
> 	public function setLastAttribute($value)
> 	{
> 		$this->lastAttribute = $value;
> 	}

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 32 remaining solutions by signing in and submitting your own entry
#33 Eric Potter / @pottereric - Score: 262 - 03/03/14 @ 02:57
:4,6s/\S/private $&<CR>A;<Esc>ka;<Esc>kA;<CR><CR>public functino<BS><BS>on getX()<CR>{<CR><Tab>return this<BS><BS><BS><BS>$this->X;<CR><BS>}<CR><Esc>:6,10y<CR>pfgrs<CR><CR>dwA<BS> = $value;<Esc>hcya<Esc><Up><Up>i$value<Esc>:5,15y<CR>:16<CR>p:28<CR>p:39<CR>dd:5,15s/X/firstProperty<CR>:17,27s/X/secondItem<CR>:29,39//<BS><BS>s/X/lastAttribute<CR>:%s/tf/tF<CR>:%s/ts/tS<CR>:%s/tl/tL<CR>ZZ

0 comments


Created by: @khamer

33 active golfers, 88 entries

Leaderboard (lowest score wins):
102
#1 - Urtica dioica / @udioica

03/02/2014 at 02:22PM

102
#2 - John Braxler / @braxler

03/13/2014 at 09:28PM

102
#3 - Peppa Pig / @PeppaPigSg

08/10/2024 at 12:24AM

103
#4 - Geraint Hywel / @g_mawr

03/01/2014 at 08:58PM

108
#5 - MP / @Enemy_m

02/27/2014 at 01:16AM

111
#6 - grey wolfs / @grey_wolfs

02/27/2014 at 09:59AM

114
#7 - Matthew Draper / @_matthewd

02/26/2014 at 05:15PM

115
#8 - John Meisner / @jmeisned

06/27/2014 at 01:18AM

119
#9 - cj / @cj01101

02/26/2014 at 11:18PM

122
#10 - Marcin Cabaj / @marcincabaj

02/27/2014 at 10:14AM

122
#11 - Nathan / @NathanHarperoni

03/01/2014 at 11:33PM

123
#12 - Carlos A Henríquez Q / @lagunex

01/18/2015 at 10:30PM

125
#13 - Joonas Pihlajamaa / @jokkebk

03/20/2014 at 08:26AM

127
#14 - Bart Nagel / @bjnagel

04/16/2014 at 12:12AM

129
#15 - Jack Jacquemmoz / @MozJack

02/26/2014 at 04:35PM

132
#16 - Jonas K. / @geratheon

02/28/2014 at 04:20PM

135
#17 - Hannes Remahl / @hannesr

02/27/2014 at 09:55PM

140
#18 - Konrad / @zichul

03/08/2014 at 01:44AM

140
#19 - Ram Tamtam / @ramtamtamtam

06/30/2014 at 11:27AM

142
#20 - Trevor Powell / @DoomedBunnies

02/27/2014 at 06:59AM

146
#21 - Omid Houshyar / @ohoushyar

02/26/2014 at 04:37AM

149
#22 - kAworu / @only4vimgolf

03/12/2014 at 02:30PM

149
#23 - sprmgik / @sprmgik

03/13/2014 at 02:24AM

150
#24 - ChoongHoe Chow / @chnibbled

02/26/2014 at 06:49AM

154
#25 - Kevin Gillieron / @gilliek42

03/12/2014 at 01:26PM

154
#26 - ところたん / @tokoro10g

04/06/2014 at 03:21PM

156
#27 - Rolinh / @Rolinh42

03/12/2014 at 01:26PM

158
#28 - Ricardo M. Vilchis / @ajkaanbal

02/26/2014 at 03:14PM

160
#29 - Pedro Santos / @pedrosans

02/26/2014 at 05:09PM

166
#30 - Brian Olpin / @bolpin

03/25/2014 at 05:16AM