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 25 remaining solutions by signing in and submitting your own entry
#26 Rolinh / Rolinh42 - Score: 156 - 03/12/14 @ 13:26
4Gqaywiprivate $<Esc>A;<CR><CR>public function <Esc>pbvgUiget<Esc>A()<CR>{<CR><Tab>return $this-><Esc>p<Esc>A;<CR><BS>}<CR><CR>public function <Esc>pbvgUiset<Esc>A($value)<CR>{<CR><Tab>$this-><Esc>p<Esc>A = $value;<CR><BS>}<CR><Esc>qw@aw@addZZ

0 comments

#27 Ricardo M. Vilchis / ajkaanbal - Score: 158 - 02/26/14 @ 15:14
3jqqw"adwAprivate $<C-R>a;<CR><CR>public function get<C-R>a<Esc>b3l~A()<CR>{<CR><Tab>return $this-><C-R>a;<CR><BS>}<CR><CR>public function set<C-R>a<Esc>b3l~<Esc>A()<BS>$value)<CR>{<CR><Tab>$this-><C-R>a = $value;<CR><BS>}<CR><BS>q<BS><Esc>qj2@q<Esc>ddZZ

0 comments

#28 Pedro Santos / pedrosans - Score: 160 - 02/26/14 @ 17:09
6wqqywiprivate $<End>;<CR><BS><CR><Tab>public function get<C-R>"()<CR>{<Esc>kftftl~jo<Tab>return $this->f<BS><C-R>";<CR><BS>}<CR><BS><CR><Tab>public function <C-R>"<Esc>b~hiset<End>($value)<CR>{<CR><Tab>$this-><C-R>" = $value;<CR><BS>}<CR><BS>w<BS><Esc>wq2@qkddZZ

0 comments

#29 Brian Olpin / bolpin - Score: 166 - 03/25/14 @ 05:16
/f<CR>qaywiprivate $<Esc>A;<CR><CR>public function <Esc>pbvgUiget<Esc>A()<CR>{<CR><Tab>return $this-><Esc>pA;<CR>}<BS><BS>}<CR><CR>public function <Esc>pbvgUiset<Esc>A($value)<CR>{<CR><Tab>$this->fir<BS><BS><BS><Esc>p =bA = $value;<CR><BS>}<CR><Esc>wq@a@akddZZ

0 comments

#30 Lucius L. Hilley III / unkmar - Score: 176 - 02/27/14 @ 07:01
iprivate $z;<CR><CR>public function getz()<CR>{<CR><Tab>return $this->z;<CR><C-H>}<CR><CR>pu<C-N> fu<C-N> setz($value)<CR>{<CR><Tab>$t<C-N>->z = $v<C-N>;<CR><C-H>}<CR><CR><Esc>kVgg"zd5jqq"zpkw"dwkl"wdwjkddV10j>gv:s:z:<C-R>w<CR>2kw3l~h5k~3kbq2@q15Gk:39d|x<CR>

0 comments

#31 RobertT / techrt2050 - Score: 209 - 02/26/14 @ 03:08
Mqqdwaprivate $;<Esc>Po<CR>get()<Esc>%Po{<CR><Tab>return $this->;<Esc>Po<BS>}<CR><CR>set($value)<Esc>%Po{<CR><Tab>$this-> = $value;<Esc>2F Po<BS>}<CR><Esc>+q2@qkdd:g/(/s/\(.et\(.\<Left><Right><BS><BS><BS>)\(.\)\.*\)$/public function \1\u\2\3/<CR><CR>:<Up><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Right>(<CR>:wq<CR>

0 comments

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

32 active golfers, 86 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

103
#3 - Geraint Hywel / g_mawr

03/01/2014 at 08:58PM

108
#4 - MP / Enemy_m

02/27/2014 at 01:16AM

111
#5 - grey wolfs / grey_wolfs

02/27/2014 at 09:59AM

114
#6 - Matthew Draper / _matthewd

02/26/2014 at 05:15PM

115
#7 - John Meisner / jmeisned

06/27/2014 at 01:18AM

119
#8 - cj / cj01101

02/26/2014 at 11:18PM

122
#9 - Marcin Cabaj / marcincabaj

02/27/2014 at 10:14AM

122
#10 - Nathan / NathanHarperoni

03/01/2014 at 11:33PM

123
#11 - Carlos A Henríquez Q / lagunex

01/18/2015 at 10:30PM

125
#12 - Joonas Pihlajamaa / jokkebk

03/20/2014 at 08:26AM

127
#13 - Bart Nagel / bjnagel

04/16/2014 at 12:12AM

129
#14 - Jack Jacquemmoz / MozJack

02/26/2014 at 04:35PM

132
#15 - Jonas K. / geratheon

02/28/2014 at 04:20PM

135
#16 - Hannes Remahl / hannesr

02/27/2014 at 09:55PM

140
#17 - Konrad / zichul

03/08/2014 at 01:44AM

140
#18 - Ram Tamtam / ramtamtamtam

06/30/2014 at 11:27AM

142
#19 - Trevor Powell / DoomedBunnies

02/27/2014 at 06:59AM

146
#20 - Omid Houshyar / ohoushyar

02/26/2014 at 04:37AM

149
#21 - kAworu / only4vimgolf

03/12/2014 at 02:30PM

149
#22 - sprmgik / sprmgik

03/13/2014 at 02:24AM

150
#23 - ChoongHoe Chow / chnibbled

02/26/2014 at 06:49AM

154
#24 - Kevin Gillieron / gilliek42

03/12/2014 at 01:26PM

154
#25 - 闇を切り裂く非線形システム少女ところたん / tokoro10g

04/06/2014 at 03:21PM

156
#26 - Rolinh / Rolinh42

03/12/2014 at 01:26PM

158
#27 - Ricardo M. Vilchis / ajkaanbal

02/26/2014 at 03:14PM

160
#28 - Pedro Santos / pedrosans

02/26/2014 at 05:09PM

166
#29 - Brian Olpin / bolpin

03/25/2014 at 05:16AM

176
#30 - Lucius L. Hilley III / unkmar

02/27/2014 at 07:01AM

209
#31 - RobertT / techrt2050

02/26/2014 at 03:08AM

262
#32 - Eric Potter / pottereric

03/03/2014 at 02:57AM