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

63 active golfers, 254 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

65
#3 - Qing Liu / @poeminlash

08/09/2022 at 06:12AM

65
#4 - Peppa Pig / @PeppaPigSg

07/03/2024 at 08:04AM

65
#5 - nickGPT / @nickandbro

08/28/2024 at 10:43PM

67
#6 - Abdel Said / @abdelsaid

05/10/2013 at 01:20PM

68
#7 - You-Siang Lin / @yslinnctu

11/28/2011 at 07:50AM

68
#8 - Renat Aksitov / @Korvin79

02/27/2012 at 10:18PM

69
#9 - Justin Love / @wondible

09/19/2011 at 01:27AM

71
#10 - Tim Chase / @gumnos

07/31/2011 at 11:16PM

71
#11 - Tim Tsu / @vimgolfpunk

09/04/2011 at 08:18AM

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

07/31/2011 at 01:23PM

77
#13 - William Dunand / @wdunand

02/24/2012 at 07:31AM

78
#14 - Mohammed / @mbadran

09/01/2011 at 12:09PM

81
#15 - Trevor Powell / @DoomedBunnies

11/29/2011 at 03:40AM

81
#16 - Gabriel Barta / @gbarta

12/03/2011 at 02:50AM

81
#17 - Raúl Jara / @rauljara

07/16/2012 at 03:06PM

81
#18 - Emile Swarts / @EmileSwarts

09/02/2012 at 09:21AM

82
#19 - Junfeng / @junfeng

08/05/2011 at 11:37AM

82
#20 - Stanley Wang / @stanleynwang

08/25/2011 at 11:09AM

83
#21 - Dave / @zzdave13

07/28/2011 at 09:44PM

84
#22 - Yann Moisan / @YannMoisan

01/25/2013 at 11:00AM

85
#23 - akhilravidas / @akhilravidas

07/31/2011 at 01:12PM

87
#24 - Xavier Nayrac / @lkdjiin

01/02/2012 at 05:23PM

88
#25 - Sergi Sorribas / @lerovitch

08/29/2011 at 01:56PM

89
#26 - Nonayo Biznast / @NonayoBiznast

09/04/2011 at 05:20PM

90
#27 - Lily / @lilibethdlc

08/30/2011 at 07:06PM

90
#28 - Deniz Ugurlu / @Den1z

01/31/2012 at 12:01AM

91
#29 - @AndrewRadev@hachyderm.io / @andrewradev

07/30/2011 at 08:22PM

91
#30 - じょんあば / @john_ababa

02/28/2012 at 03:21PM