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 55ff7ea45a2b52043e06dee2

Forgot to follow the naming convention...

Rename everything like MY_VAR_SOMETHING to MyVarSomething.

Start file
int WaterAdder::OnTimer(Universe u)
{
  const int MY_VAR_TYPE_ID = Universe::TYPE_ID_PLANETARY_SYSTEM;
  Universe::Object MY_VAR_SUN_TEMPLATE;
  this->InitializeTheSun(MY_VAR_SUN_TEMPLATE);

  // auto & MY_VAR_BRIGHT_STAR = ptheir_->StarClass("G2V");
  // Fails after some time passes in u:
  // Assert(Universe::IsElement(MY_VAR_SUN_TEMPLATE, MY_VAR_BRIGHT_STAR));

  // Just to doublecheck.
  Assert(MY_VARIANT(ptheir_->OTHER_GUYS_VAR).IsEqual(MY_VAR_SUN_TEMPLATE));

  // TODO: initialize MY_VAR_EARTH_TEMPLATE

  Universe::TYPE_ID_INFO<MY_VAR_TYPE_ID>::Type MY_VAR_SOLAR_SYSTEM_TEMPLATE();
  MY_VAR_SOLAR_SYSTEM_TEMPLATE.Add({MY_VAR_SUN_TEMPLATE,
    ptheir_->THEIR_VAR_MERCURY, ptheir_->THEIR_VAR_VENUS,
    MY_VAR_EARTH_TEMPLATE});

  Universe::TYPE_ID_INFO<MY_VAR_TYPE_ID>::Type *MY_VAR_SOLAR_SYSTEM =
    u.SearchByTemplate<MY_VAR_TYPE_ID>(MY_VAR_SOLAR_SYSTEM_TEMPLATE);
  Assert(MY_VARIABLE_CHECK(MY_VAR_SOLAR_SYSTEM));
  
  auto & MY_VAR_SUN = MY_VAR_SOLAR_SYSTEM->GetStar(0);
  auto MY_VAR_MASS = MY_VAR_SUN.GetMass();
  auto MY_VAR_DIST = Universe::Quantity::Meters(MY_VAR_MASS.InKg() * 1e-20);
  Universe::Quantity::VELOCITY_T::Type v;
  Assert(GeneralRelativity::GetOrbitalVelocity(u, MY_VAR_MASS,
    MY_VAR_DIST, &v));
  auto MY_VAR_VELOCITY = vector4<Universe::Quantity::TYPE_SPEED::Type>::From3(
    GeneralRelativity::c, rnd.UnitVector3() * v);
  vector3 MY_VAR_POSITION = GeneralRelativity::RegularizedShift(u, 
    MY_VAR_SUN.GetPos(), rnd.UnitVector3(), MY_VAR_DIST);
  auto MY_VAR_WATER_MASS = std::max( MY_VAR_MASS * 4e-17,
    Universe::Quantity::Kg(63311*1.0e9));

  // Let the fun begin.
  WaterAdder::AddWater(u, MY_VAR_WATER_MASS, MY_VAR_POSITION, MY_VAR_VELOCITY);

  WaterAdder::SetTimer(Universe::Quantity::Second());
}
// TODO: Don't use long variable names like
// MY_VAR_SOLAR_SYSTEM_TEMPLATE_CHECKER_FOR_WATER_ADDER
End file
int WaterAdder::OnTimer(Universe u)
{
  const int MyVarTypeId = Universe::TYPE_ID_PLANETARY_SYSTEM;
  Universe::Object MyVarSunTemplate;
  this->InitializeTheSun(MyVarSunTemplate);

  // auto & MyVarBrightStar = ptheir_->StarClass("G2V");
  // Fails after some time passes in u:
  // Assert(Universe::IsElement(MyVarSunTemplate, MyVarBrightStar));

  // Just to doublecheck.
  Assert(MY_VARIANT(ptheir_->OTHER_GUYS_VAR).IsEqual(MyVarSunTemplate));

  // TODO: initialize MyVarEarthTemplate

  Universe::TYPE_ID_INFO<MyVarTypeId>::Type MyVarSolarSystemTemplate();
  MyVarSolarSystemTemplate.Add({MyVarSunTemplate,
    ptheir_->THEIR_VAR_MERCURY, ptheir_->THEIR_VAR_VENUS,
    MyVarEarthTemplate});

  Universe::TYPE_ID_INFO<MyVarTypeId>::Type *MyVarSolarSystem =
    u.SearchByTemplate<MyVarTypeId>(MyVarSolarSystemTemplate);
  Assert(MY_VARIABLE_CHECK(MyVarSolarSystem));
  
  auto & MyVarSun = MyVarSolarSystem->GetStar(0);
  auto MyVarMass = MyVarSun.GetMass();
  auto MyVarDist = Universe::Quantity::Meters(MyVarMass.InKg() * 1e-20);
  Universe::Quantity::VELOCITY_T::Type v;
  Assert(GeneralRelativity::GetOrbitalVelocity(u, MyVarMass,
    MyVarDist, &v));
  auto MyVarVelocity = vector4<Universe::Quantity::TYPE_SPEED::Type>::From3(
    GeneralRelativity::c, rnd.UnitVector3() * v);
  vector3 MyVarPosition = GeneralRelativity::RegularizedShift(u, 
    MyVarSun.GetPos(), rnd.UnitVector3(), MyVarDist);
  auto MyVarWaterMass = std::max( MyVarMass * 4e-17,
    Universe::Quantity::Kg(63311*1.0e9));

  // Let the fun begin.
  WaterAdder::AddWater(u, MyVarWaterMass, MyVarPosition, MyVarVelocity);

  WaterAdder::SetTimer(Universe::Quantity::Second());
}
// TODO: Don't use long variable names like
// MyVarSolarSystemTemplateCheckerForWaterAdder

View Diff

3,5c3,5
<   const int MY_VAR_TYPE_ID = Universe::TYPE_ID_PLANETARY_SYSTEM;
<   Universe::Object MY_VAR_SUN_TEMPLATE;
<   this->InitializeTheSun(MY_VAR_SUN_TEMPLATE);
---
>   const int MyVarTypeId = Universe::TYPE_ID_PLANETARY_SYSTEM;
>   Universe::Object MyVarSunTemplate;
>   this->InitializeTheSun(MyVarSunTemplate);
7c7
<   // auto & MY_VAR_BRIGHT_STAR = ptheir_->StarClass("G2V");
---
>   // auto & MyVarBrightStar = ptheir_->StarClass("G2V");
9c9
<   // Assert(Universe::IsElement(MY_VAR_SUN_TEMPLATE, MY_VAR_BRIGHT_STAR));
---
>   // Assert(Universe::IsElement(MyVarSunTemplate, MyVarBrightStar));
12c12
<   Assert(MY_VARIANT(ptheir_->OTHER_GUYS_VAR).IsEqual(MY_VAR_SUN_TEMPLATE));
---
>   Assert(MY_VARIANT(ptheir_->OTHER_GUYS_VAR).IsEqual(MyVarSunTemplate));
14c14
<   // TODO: initialize MY_VAR_EARTH_TEMPLATE
---
>   // TODO: initialize MyVarEarthTemplate
16,17c16,17
<   Universe::TYPE_ID_INFO<MY_VAR_TYPE_ID>::Type MY_VAR_SOLAR_SYSTEM_TEMPLATE();
<   MY_VAR_SOLAR_SYSTEM_TEMPLATE.Add({MY_VAR_SUN_TEMPLATE,
---
>   Universe::TYPE_ID_INFO<MyVarTypeId>::Type MyVarSolarSystemTemplate();
>   MyVarSolarSystemTemplate.Add({MyVarSunTemplate,
19c19
<     MY_VAR_EARTH_TEMPLATE});
---
>     MyVarEarthTemplate});
21,23c21,23
<   Universe::TYPE_ID_INFO<MY_VAR_TYPE_ID>::Type *MY_VAR_SOLAR_SYSTEM =
<     u.SearchByTemplate<MY_VAR_TYPE_ID>(MY_VAR_SOLAR_SYSTEM_TEMPLATE);
<   Assert(MY_VARIABLE_CHECK(MY_VAR_SOLAR_SYSTEM));
---
>   Universe::TYPE_ID_INFO<MyVarTypeId>::Type *MyVarSolarSystem =
>     u.SearchByTemplate<MyVarTypeId>(MyVarSolarSystemTemplate);
>   Assert(MY_VARIABLE_CHECK(MyVarSolarSystem));
25,27c25,27
<   auto & MY_VAR_SUN = MY_VAR_SOLAR_SYSTEM->GetStar(0);
<   auto MY_VAR_MASS = MY_VAR_SUN.GetMass();
<   auto MY_VAR_DIST = Universe::Quantity::Meters(MY_VAR_MASS.InKg() * 1e-20);
---
>   auto & MyVarSun = MyVarSolarSystem->GetStar(0);
>   auto MyVarMass = MyVarSun.GetMass();
>   auto MyVarDist = Universe::Quantity::Meters(MyVarMass.InKg() * 1e-20);
29,31c29,31
<   Assert(GeneralRelativity::GetOrbitalVelocity(u, MY_VAR_MASS,
<     MY_VAR_DIST, &v));
<   auto MY_VAR_VELOCITY = vector4<Universe::Quantity::TYPE_SPEED::Type>::From3(
---
>   Assert(GeneralRelativity::GetOrbitalVelocity(u, MyVarMass,
>     MyVarDist, &v));
>   auto MyVarVelocity = vector4<Universe::Quantity::TYPE_SPEED::Type>::From3(
33,35c33,35
<   vector3 MY_VAR_POSITION = GeneralRelativity::RegularizedShift(u, 
<     MY_VAR_SUN.GetPos(), rnd.UnitVector3(), MY_VAR_DIST);
<   auto MY_VAR_WATER_MASS = std::max( MY_VAR_MASS * 4e-17,
---
>   vector3 MyVarPosition = GeneralRelativity::RegularizedShift(u, 
>     MyVarSun.GetPos(), rnd.UnitVector3(), MyVarDist);
>   auto MyVarWaterMass = std::max( MyVarMass * 4e-17,
39c39
<   WaterAdder::AddWater(u, MY_VAR_WATER_MASS, MY_VAR_POSITION, MY_VAR_VELOCITY);
---
>   WaterAdder::AddWater(u, MyVarWaterMass, MyVarPosition, MyVarVelocity);
44c44
< // MY_VAR_SOLAR_SYSTEM_TEMPLATE_CHECKER_FOR_WATER_ADDER
---
> // MyVarSolarSystemTemplateCheckerForWaterAdder

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 7 remaining solutions by signing in and submitting your own entry
#8 aisapatino / aisapatino - Score: 48 - 09/23/15 @ 21:58
:%s/\vM(Y_VAR_\w+)/M\L\1/g<CR>:%s/\v_(\l)/\U\1/g<CR>ZZ

0 comments

#9 Robert Goeddel / f0rdpr3fect - Score: 49 - 11/11/15 @ 23:55
:%s/M\(Y_VAR_\h\+\)/M\L\1/g<CR>:%s/_\(\l\)/\u\1/g<CR>ZZ

0 comments

Created by: vikasatkin

9 active golfers, 18 entries

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

10/08/2015 at 11:38PM

32
#2 - Petro Тrouq / zulolosi

10/13/2015 at 07:39PM

32
#3 - John Braxler / braxler

10/14/2015 at 04:01PM

32
#4 - 何晨 / hechen0_

09/22/2016 at 05:23PM

32
#5 - 杨洋 / 176795444

07/03/2017 at 07:25AM

34
#6 - Jon Krause / jkrause314

01/18/2016 at 11:06PM

35
#7 - esquifit / henroboke

10/10/2015 at 05:52PM

48
#8 - aisapatino / aisapatino

09/23/2015 at 09:58PM

49
#9 - Robert Goeddel / f0rdpr3fect

11/11/2015 at 11:55PM