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 4e379f2fdfb67a000100002e

PHP <--> Java class conversion Part 2

Same class but reverse!

Start file
public class Foo
{
	private double var1;
	private double var2;

	public Foo(double val)
	{
		init(val);
		doSomething();
	}

	private void init(double val)
	{
		var1 = val;
	}
	
	private void doSomething()
	{
		var2 = Math.sqrt(var1);
	}

	public double getResult()
	{
		return var2;
	}
}
End file
<?php
class Foo
{
	private $var1;
	private $var2;

	public function Foo($val)
	{
		$this->init($val);
		$this->doSomething();
	}

	private function init($val)
	{
		$this->var1 = $val;
	}
	
	private function doSomething()
	{
		$this->var2 = sqrt($this->var1);
	}

	public function getResult()
	{
		return $this->var2;
	}
}
?>

View Diff

1c1,2
< public class Foo
---
> <?php
> class Foo
3,4c4,5
< 	private double var1;
< 	private double var2;
---
> 	private $var1;
> 	private $var2;
6c7
< 	public Foo(double val)
---
> 	public function Foo($val)
8,9c9,10
< 		init(val);
< 		doSomething();
---
> 		$this->init($val);
> 		$this->doSomething();
12c13
< 	private void init(double val)
---
> 	private function init($val)
14c15
< 		var1 = val;
---
> 		$this->var1 = $val;
17c18
< 	private void doSomething()
---
> 	private function doSomething()
19c20
< 		var2 = Math.sqrt(var1);
---
> 		$this->var2 = sqrt($this->var1);
22c23
< 	public double getResult()
---
> 	public function getResult()
24c25
< 		return var2;
---
> 		return $this->var2;
26a28
> ?>

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 28 remaining solutions by signing in and submitting your own entry
#29 Simon's Calf / simonscarfe - Score: 144 - 09/15/11 @ 13:59
cw<?php<CR><Esc>:%s/double /\$<CR>7Gwifunction <Esc>2jI$this-><Esc>j.5j.5j.9Gfvi$<Esc>:%s/void/function<CR>15Gwwwwwi$<Esc>5jdf.fvi$this-><Esc>jjjF$clfunction <Esc>jji$this-><Esc>Go?><Esc>ZZ

0 comments

#30 ise0615 / ise0615 - Score: 144 - 05/05/12 @ 11:26
R<?php<CR><Esc>xx:%s/double /\$/g<CR>wxipublic<BS><BS><BS><BS><BS><BS>function <Esc>bvwhy5kp5kbbP5kk3bPjjbi$<Esc>^i$this-.<BS>><Esc>^j.5j^.5j^.5jl.5k3wwl.4bbbvwd5ki$<Esc>kkbvwhd5jvwhdGa<CR>?><Esc>ZZ

0 comments

#31 David Andrews / k00ka - Score: 147 - 08/03/11 @ 14:51
i<?php<CR><Esc>dw:%s/double /\$<CR>:%s/void/function<CR>:%s/<Tab><Tab>/<Tab><Tab>\$this-><CR>:%s/c /c function <CR>/\$<CR>xn3dwe p:%s/\([^\$]\)val/\1\$val<CR>/M<CR>dwx/(<CR>a$this-><Esc>Go?><Esc><CR>:w<CR>:q<CR>

0 comments

#32 Terrance Kennedy / Cyphus - Score: 147 - 08/18/11 @ 16:14
cw<?php<CR>:<BS><Esc>:%s/double /$/<CR>wxwWWwi$this-><Esc>?{<CR>nw.$bb.nnw.nnw.W.NwWwi$<Esc>:%s/void/function/<CR>/pu<CR>wifunction <Esc>nwi<Esc>.lafunction <Esc>20Gwwwwwdwx9Gwwwwa$<Esc>Go?><Esc>ZZ

0 comments

#33 Roel Bondoc / roelbondoc - Score: 148 - 01/30/12 @ 14:45
dwO<?php<Esc><Esc>Go?><Esc><Esc>:%s/double /$/<CR>:%s/void/function<CR>:%s/var/$this->var/gc<CR>nnyyyy:7<CR>wifunction <Esc>:23<CR>w.lx:9<CR><C-V>jI$this-><Esc>wwwwli$<Esc>:15<CR>$bi$<Esc>:20<CR>wwwwwdwx<Esc>:wq<CR>

0 comments

#34 Gregory Igelmund / grekko - Score: 180 - 12/06/11 @ 22:18
cw<?php<CR><Esc>:%s/double //g<CR>:%s/c /c function/g<CR>u:<Up><Left><Left> <CR>:%s/var/$v<BS>this->var/g<CR>4Gf$df>i$<Esc>hjldf>i$<Esc>9Gi$this-><Esc>hj^^i$this-><Esc>:%s/val/$vak/<BS><BS>l/g<CR>:%s(<BS>/vp<BS>oid/function/g<CR>20GfMdwx$Go<?<BS><BS>?><Esc>ZZ

0 comments

#35 Sergey Kim / skim1776 - Score: 227 - 08/05/11 @ 05:27
O<?php<Esc>jldbxx<F2>jwwdwi$<Esc>jdwi$<Esc>jjhifunction <Esc>wwdwdwi($<Esc>jj^R$this <BS>->init($val);<Esc>j^i$this-><Esc>j2<Esc>jjhdbifunction <Esc>wwwdwi$<Esc>jj^i$this-><Esc>wwwi$<Esc>jjjbbdwfuifunction <Esc>jj^i$this-><Esc>wwwdwxww$uxwa$this-><Esc>jjjbbbdwifunction <Esc>jji$this-><Esc>jjj<CR>A<CR>?><Esc>ZZ

0 comments

Created by: robrob12

35 active golfers, 83 entries

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

01/17/2013 at 06:35PM

80
#2 - John Braxler / braxler

09/30/2014 at 07:04PM

87
#3 - Renat Aksitov / Korvin79

02/27/2012 at 11:27PM

88
#4 - Justin Love / wondible

09/23/2011 at 04:23AM

88
#5 - You-Siang Lin / yslinnctu

11/29/2011 at 12:24AM

88
#6 - Abdel Said / abdelsaid

03/14/2012 at 11:50AM

93
#7 - Tim Chase / gumnos

08/03/2011 at 11:46AM

94
#8 - h_east (トロッコ6個) / h_east

08/03/2011 at 05:04AM

94
#9 - Stanley Wang / stanleynwang

08/28/2011 at 01:46AM

103
#10 - deris / deris0126

04/04/2012 at 04:37PM

104
#11 - Joshua Moyers / joshuamoyers

08/03/2011 at 06:40AM

106
#12 - Tim Tsu / vimgolfpunk

09/04/2011 at 02:03PM

106
#13 - Jer Wilson / superjercom

10/28/2011 at 10:08AM

106
#14 - Woojung Kim 김우중 / _kimwz

07/16/2013 at 05:46AM

107
#15 - Hu Junfeng / junfeng

08/11/2011 at 11:45AM

115
#16 - William Dunand / wdunand

02/21/2012 at 08:44AM

121
#17 - Tesnorth / Tesnorth

02/05/2012 at 12:42PM

121
#18 - 無ん垢の叫び / john_ababa

02/28/2012 at 03:48PM

124
#19 - Petro Verkhogliad / vpetro

08/28/2011 at 09:48PM

125
#20 - Dan Masquelier / danmasq

08/04/2011 at 06:31AM

125
#21 - Sergi Sorribas / lerovitch

08/25/2011 at 06:50AM

127
#22 - not so punk :] / notsopunk

08/12/2011 at 09:46PM

130
#23 - Christopher Erin / MCNormalMode

09/17/2011 at 08:53PM

131
#24 - Andrew Radev / andrewradev

08/26/2011 at 11:43AM

131
#25 - Dühöngő / aswna

09/05/2011 at 04:53PM

132
#26 - pcdude2143 / pcdude2143

07/04/2013 at 09:52PM

133
#27 - Ryan Menezes / rydmen

09/20/2011 at 08:09AM

138
#28 - jacobcr / jacobcr

08/23/2011 at 04:03PM

144
#29 - Simon's Calf / simonscarfe

09/15/2011 at 01:59PM

144
#30 - ise0615 / ise0615

05/05/2012 at 11:26AM

147
#31 - David Andrews / k00ka

08/03/2011 at 02:51PM

147
#32 - Terrance Kennedy / Cyphus

08/18/2011 at 04:14PM

148
#33 - Roel Bondoc / roelbondoc

01/30/2012 at 02:45PM

180
#34 - Gregory Igelmund / grekko

12/06/2011 at 10:18PM

227
#35 - Sergey Kim / skim1776

08/05/2011 at 05:27AM