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):
91
#31 - Peter Anselmo / @peter_anselmo

03/08/2012 at 12:39AM

92
#32 - jacobcr / @jacobcr

08/25/2011 at 07:46PM

93
#33 - cj / @cj01101

02/07/2014 at 10:59PM

95
#34 - Daniel Lundin / @danielundin

07/04/2012 at 01:38PM

96
#35 - not so punk :] / @notsopunk

08/12/2011 at 07:41AM

98
#36 - fsj / @FrogzSJ

08/12/2018 at 08:17PM

98
#37 - Sean Dewar / @seandewar

09/18/2020 at 10:01PM

100
#38 - Jason Felice / @eraserhd

11/22/2011 at 01:00AM

101
#39 - POSIX / @po6ix

01/31/2022 at 05:48PM

109
#40 - Dühöngő / @aswna

09/06/2011 at 07:24PM

109
#41 - Oliver Christ / @0liverChrist

11/08/2013 at 10:22PM

113
#42 - Neil / @spameldoon

08/21/2011 at 11:30AM

113
#43 - Ben Friedland / @bfriedland174

05/23/2012 at 08:54AM

114
#44 - Terrance Kennedy / @Cyphus

08/18/2011 at 05:06AM

115
#45 - ltn614 / @ltn614

10/26/2015 at 02:29PM

124
#46 - Tomasz Walotek / @uolot

08/25/2011 at 07:47PM

124
#47 - Feanor Celebrimbor / @tumbaletaurea

06/04/2012 at 03:52AM

127
#48 - James / @Dronak

09/21/2014 at 01:57AM

128
#49 - Dan Masquelier / @danmasq

08/04/2011 at 02:45AM

129
#50 - Matthew Beaumont / @mattybeau_dev

11/26/2021 at 03:19PM

137
#51 - Simon Scarfe / @simonscarfe

09/15/2011 at 02:16PM

137
#52 - Chris Ford / @ctford

10/20/2013 at 02:26PM

138
#53 - keikun / @funkaloo

08/13/2011 at 10:33PM

138
#54 - Jonathan Bennett / @jonbca7

11/24/2011 at 05:49AM

140
#55 - Nikita Mikhaylov / @nslqqq

04/25/2012 at 01:36PM

145
#56 - spatz / @jugglindetritus

07/09/2012 at 02:51AM

146
#57 - Nolen Royalty / @NolenRoyalty

02/19/2012 at 09:28PM

147
#58 - Fernando Ortiz / @fortiz2k

06/17/2012 at 09:53AM

153
#59 - Andrey Andreev / @andro_a

07/29/2011 at 02:06PM

153
#60 - Aviv Ben-Yosef / @avivby

07/29/2011 at 03:31PM