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

PHP <--> Java class conversion Part 1

Convert this tiny php class to adequate java one.

Start 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;
	}
}
?>
End 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;
	}
}

View Diff

1,2c1
< <?php
< class Foo
---
> public class Foo
4,5c3,4
< 	private $var1;
< 	private $var2;
---
> 	private double var1;
> 	private double var2;
7c6
< 	public function Foo($val)
---
> 	public Foo(double val)
9,10c8,9
< 		$this->init($val);
< 		$this->doSomething();
---
> 		init(val);
> 		doSomething();
13c12
< 	private function init($val)
---
> 	private void init(double val)
15c14
< 		$this->var1 = $val;
---
> 		var1 = val;
18c17
< 	private function doSomething()
---
> 	private void doSomething()
20c19
< 		$this->var2 = sqrt($this->var1);
---
> 		var2 = Math.sqrt(var1);
23c22
< 	public function getResult()
---
> 	public double getResult()
25c24
< 		return $this->var2;
---
> 		return var2;
28d26
< ?>

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 44 remaining solutions by signing in and submitting your own entry
#45 Chris Ford / ctford - Score: 137 - 10/20/13 @ 14:26
ddipublic <Esc>:%/<BS>s/e \$/e double <CR>:%s/\$this->//g<CR>/%s<BS><BS><BS>:%s/function/void<CR>Wcwdouble<Esc>:6<CR>Wdw<Esc>:%s/\$val/double val<CR>WWdw6khhdw11jlliMath.<Esc>GddZZ

0 comments

#46 keikun / funkaloo - Score: 138 - 08/13/11 @ 22:33
:%s/\$//g|%s/this->//g|%s/e v/e double v/g|%s/sq/Math.sq/g|%s/(v/(double v/gc<CR>ynynggddipublic <Esc>/function<CR>dwncwvoid<Esc>ncwvoid<Esc>ncwdouble<Esc>GddZZ

0 comments

#47 Jonathan Bennett / jonbca7 - Score: 138 - 11/24/11 @ 05:49
ddipub<C-N> <Esc>/fu<CR>df n.ivoid <Esc>n.<Esc>df i <Esc>ncwdouble<Esc>/$th<CR>qvdf>nq@v@@@@@@./<Esc><Esc>/$<CR>n//$v<BS><BS><BS>$<CR>n/$v<CR>xidouble <Esc>n.lxn.ido<C-N><C-N> <Esc>nxn.ido<C-N><C-N> <Esc>nx/sq<CR>iMath.<Esc>GddZZ

0 comments

#48 Nikita Mikhaylov / nslqqq - Score: 140 - 04/25/12 @ 13:36
ddipublic <Esc>2jea double<Esc>jbidouble <Esc>2jdbxf$idouble <Esc>6jdbivoid <Esc>f$idouble <Esc>5jbdbivoid <Esc>2jfsiMath.<Esc>3jbbdbidouble <Esc>9jdd:%s/this->//g<CR>:%s/\$//g<CR>ZZ

0 comments

#49 spatz / jugglindetritus - Score: 145 - 07/09/12 @ 02:51
ddipublic <Esc>Ldd:%s/$this-.<BS>>//g<CR>:%s/function //g<CR>:%s/$val/val/gc<CR>nyny:%s/\$/double /g<CR>:%s/ate /ate void /gc<CR>nnyy2jwewwiMath.<Esc>3j2bidouble :<BS><Esc>:w<CR>:q<CR>

0 comments

#50 Nolen Royalty / NolenRoyalty - Score: 146 - 02/19/12 @ 21:28
ddipublic <Esc>jjf$xjxjj:%this<BS><BS><BS><BS>s/$this->//g<CR>:%s/%<BS>\$/double /g<CR>fddw6kdiwx4kbidouble <Esc>kFv.:%s/function/void/g<CR>fvciwdouble<Esc>Gdd20kfvdw13jfsiMath.<Esc>:wq<CR>

0 comments

#51 Fernando Ortiz / fortiz2k - Score: 147 - 06/17/12 @ 09:53
ddipu<C-P> <Esc>/\$<CR>cldouble <Esc>n.n.nxnxnxnxidouble <Esc>nxnxnxnxnx/function<CR>cw<BS><Esc>n.a void<Esc>n.cw<BS><BS><BS><BS><BS>void<Esc>ncwdouble<Esc>/<BS>:%s/this->/<CR>:%s/sqrt(this->/Math.sqrt(/<CR>GddZZ

0 comments

#52 Andrey Andreev / andro_a - Score: 153 - 07/29/11 @ 14:06
ddipublic <Esc>:%s/\$v/double /g<BS><BS>g<BS>v/g<CR>/fun<CR>cwviod<BS><BS><BS>oid<Esc>N.NdwNcwdozu<BS><BS>uble<Esc>/th<BS><BS>$th<CR>dtvndf>n.n.n.n.5j<0xc3><0xb6>jkkkkkkjhkklljkkjjllllllllim<BS>Math.<Esc>?dou<CR>dwnndw<Esc>GddZZ

0 comments

#53 Aviv Ben-Yosef / avivby - Score: 153 - 07/29/11 @ 15:31
ddipublic <C-C><C-C>jjwwctvdouble <C-C><C-C>jbb.jjwwwh.jjjjjjbh.kkkkkkBBBdw}jwwcwvoid<C-C><C-C>jjjjjjkb.jjjjjbciwdouble<C-C><C-C>kkkwwwwiMath.<C-C><C-C>:%s/$thi<BS><BS><BS><BS>\$this->//g<CR>:%s/\$//<CR>dduGddZZ

0 comments

#54 Sergey Kim / skim1776 - Score: 187 - 08/05/11 @ 05:30
ddipublic <Esc>jjwwidouble <Esc>lxjbbrdaouble <Esc>jjdbxxwwhxd<Esc>idouble <Esc>jjbdbdbdbwwhxjdbdbxxjjjdwivoid <Esc>wwlidouble <Esc>lxjjbhxbbdbdbdbjjjdwivoid <Esc>jjdbxxxhxwwiMath.<Esc>wwwdwh3xjjjbdbidouble <Esc>jjwdwdwxxhGddZZ

0 comments

#55 dharmapurikar / dharmapurikar - Score: 465 - 11/30/11 @ 08:19
dd:27<CR>dd/<BS>:%s/private/private double <Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left> $<Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right>/g<CR>:<Up><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Right><Right>\<CR><Esc>:%s/\$this->//g<CR>:%s/function//g<CR>u:%/pu<BS><BS>fuc<BS>nction Foo/Foo/g<CR>:<Up><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Right>s<CR><Right><Right><Right><Down><Down>:private<BS><BS><BS><BS><BS><BS><BS>%s/private function/private void/g<CR>:%s public function<BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS>/public function/public void<BS><BS><BS><BS>double/g<CR><Esc>:%s/\$val/val/g<CR>:%s/sqrt/Math.sqrt<CR>/<BS>:12<CR>WWW<Up>WW<Right><Right><Right><Right><Right><Right><Left>idouble <Esc>:w<CR><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Up><Up><Up><Up><Up><Up><Right><Right><Right><Right>idouble <Esc>:w<CR>/cla<BS><BS><BS><BS>:%s/class/public class<CR><Esc>:w<CR>:q<CR>

0 comments

Created by: robrob12

55 active golfers, 176 entries

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

07/01/2012 at 04:59AM

65
#2 - John Braxler / braxler

07/30/2014 at 09:46PM

67
#3 - Abdel Said / abdelsaid

05/10/2013 at 01:20PM

68
#4 - You-Siang Lin / yslinnctu

11/28/2011 at 07:50AM

68
#5 - Renat Aksitov / Korvin79

02/27/2012 at 10:18PM

69
#6 - Justin Love / wondible

09/19/2011 at 01:27AM

71
#7 - Tim Chase / gumnos

07/31/2011 at 11:16PM

71
#8 - Tim Tsu / vimgolfpunk

09/04/2011 at 08:18AM

72
#9 - h_east (トロッコ6個) / h_east

07/31/2011 at 01:23PM

77
#10 - William Dunand / wdunand

02/24/2012 at 07:31AM

78
#11 - Mohammed / mbadran

09/01/2011 at 12:09PM

81
#12 - Trevor Powell / DoomedBunnies

11/29/2011 at 03:40AM

81
#13 - Gabriel Barta / gbarta

12/03/2011 at 02:50AM

81
#14 - Raúl Jara / rauljara

07/16/2012 at 03:06PM

81
#15 - Emile Swarts / EmileSwarts

09/02/2012 at 09:21AM

82
#16 - Hu Junfeng / junfeng

08/05/2011 at 11:37AM

82
#17 - Stanley Wang / stanleynwang

08/25/2011 at 11:09AM

83
#18 - Dave / zzdave13

07/28/2011 at 09:44PM

84
#19 - Yann Moisan / YannMoisan

01/25/2013 at 11:00AM

85
#20 - akhilravidas / akhilravidas

07/31/2011 at 01:12PM

87
#21 - Xavier Nayrac / lkdjiin

01/02/2012 at 05:23PM

88
#22 - Sergi Sorribas / lerovitch

08/29/2011 at 01:56PM

89
#23 - Nonayo Biznast / NonayoBiznast

09/04/2011 at 05:20PM

90
#24 - Lily / lilibethdlc

08/30/2011 at 07:06PM

90
#25 - Deniz Ugurlu / Den1z

01/31/2012 at 12:01AM

91
#26 - Andrew Radev / andrewradev

07/30/2011 at 08:22PM

91
#27 - 無ん垢の叫び / john_ababa

02/28/2012 at 03:21PM

91
#28 - Peter Anselmo / peter_anselmo

03/08/2012 at 12:39AM

92
#29 - jacobcr / jacobcr

08/25/2011 at 07:46PM

93
#30 - cj / cj01101

02/07/2014 at 10:59PM

95
#31 - Daniel Lundin / danielundin

07/04/2012 at 01:38PM

96
#32 - not so punk :] / notsopunk

08/12/2011 at 07:41AM

100
#33 - Jason Felice / eraserhd

11/22/2011 at 01:00AM

109
#34 - Dühöngő / aswna

09/06/2011 at 07:24PM

109
#35 - Oliver Christ / 0liverChrist

11/08/2013 at 10:22PM

113
#36 - Neil / spameldoon

08/21/2011 at 11:30AM

113
#37 - Ben Friedland / bfriedland174

05/23/2012 at 08:54AM

114
#38 - Terrance Kennedy / Cyphus

08/18/2011 at 05:06AM

115
#39 - ltn614 / ltn614

10/26/2015 at 02:29PM

124
#40 - Tomasz Walotek / uolot

08/25/2011 at 07:47PM

124
#41 - Feanor Celebrimbor / tumbaletaurea

06/04/2012 at 03:52AM

127
#42 - James / Dronak

09/21/2014 at 01:57AM

128
#43 - Dan Masquelier / danmasq

08/04/2011 at 02:45AM

137
#44 - Simon's Calf / simonscarfe

09/15/2011 at 02:16PM

137
#45 - Chris Ford / ctford

10/20/2013 at 02:26PM

138
#46 - keikun / funkaloo

08/13/2011 at 10:33PM

138
#47 - Jonathan Bennett / jonbca7

11/24/2011 at 05:49AM

140
#48 - Nikita Mikhaylov / nslqqq

04/25/2012 at 01:36PM

145
#49 - spatz / jugglindetritus

07/09/2012 at 02:51AM

146
#50 - Nolen Royalty / NolenRoyalty

02/19/2012 at 09:28PM

147
#51 - Fernando Ortiz / fortiz2k

06/17/2012 at 09:53AM

153
#52 - Andrey Andreev / andro_a

07/29/2011 at 02:06PM

153
#53 - Aviv Ben-Yosef / avivby

07/29/2011 at 03:31PM

187
#54 - Sergey Kim / skim1776

08/05/2011 at 05:30AM

465
#55 - dharmapurikar / dharmapurikar

11/30/2011 at 08:19AM