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

39 active golfers, 98 entries

Leaderboard (lowest score wins):
79
#1 - Peppa Pig / @PeppaPi95550250

09/06/2024 at 09:13AM

80
#2 - Urtica dioica / @udioica

01/17/2013 at 06:35PM

80
#3 - John Braxler / @braxler

09/30/2014 at 07:04PM

87
#4 - Renat Aksitov / @Korvin79

02/27/2012 at 11:27PM

87
#5 - Qing Liu / @poeminlash

08/10/2022 at 04:48AM

88
#6 - Justin Love / @wondible

09/23/2011 at 04:23AM

88
#7 - You-Siang Lin / @yslinnctu

11/29/2011 at 12:24AM

88
#8 - Abdel Said / @abdelsaid

03/14/2012 at 11:50AM

93
#9 - Tim Chase / @gumnos

08/03/2011 at 11:46AM

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

08/03/2011 at 05:04AM

94
#11 - Stanley Wang / @stanleynwang

08/28/2011 at 01:46AM

103
#12 - deris / @deris0126

04/04/2012 at 04:37PM

104
#13 - Joshua Moyers / @joshuamoyers

08/03/2011 at 06:40AM

106
#14 - Tim Tsu / @vimgolfpunk

09/04/2011 at 02:03PM

106
#15 - Jer Wilson / @superjercom

10/28/2011 at 10:08AM

106
#16 - Woojung Kim 김우중 / @_kimwz

07/16/2013 at 05:46AM

107
#17 - Hu Junfeng / @junfeng

08/11/2011 at 11:45AM

115
#18 - William Dunand / @wdunand

02/21/2012 at 08:44AM

121
#19 - Tesnorth / @Tesnorth

02/05/2012 at 12:42PM

121
#20 - じょんあば / @john_ababa

02/28/2012 at 03:48PM

124
#21 - Petro Verkhogliad / @vpetro

08/28/2011 at 09:48PM

125
#22 - Dan Masquelier / @danmasq

08/04/2011 at 06:31AM

125
#23 - Sergi Sorribas / @lerovitch

08/25/2011 at 06:50AM

127
#24 - not so punk :] / @notsopunk

08/12/2011 at 09:46PM

128
#25 - RockerZZY / @rocker_zzy

06/05/2020 at 04:55AM

130
#26 - Christopher Erin / @MCNormalMode

09/17/2011 at 08:53PM

131
#27 - @AndrewRadev@hachyderm.io / @andrewradev

08/26/2011 at 11:43AM

131
#28 - Dühöngő / @aswna

09/05/2011 at 04:53PM

132
#29 - galadriel2143 / @galadriel2143

07/04/2013 at 09:52PM

133
#30 - Ryan Menezes / @rydmen

09/20/2011 at 08:09AM