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 35 remaining solutions by signing in and submitting your own entry
#36 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

36 active golfers, 103 entries

Leaderboard (lowest score wins):
158
#31 - Ricardo M. Vilchis / @ajkaanbal

02/26/2014 at 03:14PM

160
#32 - Pedro Santos / @pedrosans

02/26/2014 at 05:09PM

166
#33 - Brian Olpin / @bolpin

03/25/2014 at 05:16AM

176
#34 - Lucius L. Hilley III / @unkmar

02/27/2014 at 07:01AM

209
#35 - RobertT / @techrt2050

02/26/2014 at 03:08AM

262
#36 - Eric Potter / @pottereric

03/03/2014 at 02:57AM