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 5491377167afde00024ba4cf

Refactoring useless Method away

Real-life challenge, convert a bunch of ifs to a switch statement

Start file
if (isTyp(YBD.Typ_GEBAEUDE, currentTyp)) {
	immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
}
if (isTyp(YBD.Typ_OBJEKT, currentTyp)) {
	immobilienItem.setObjektNr(currentItem.getObjektNr());
}
if (isTyp(YBD.Typ_ETAGE, currentTyp)) {
	immobilienItem.setEtageNr(currentItem.getEtageNr());
}
if (isTyp(YBD.Typ_IMMOBILIE, currentTyp)) {
	immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
}
if (isTyp(YBD.Typ_HAUS, currentTyp)) {
	immobilienItem.setHausNr(currentItem.getHausNr());
}
End file
switch (currentTyp) {
	case YBD.Typ_GEBAEUDE:
		immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
		break;
	case YBD.Typ_OBJEKT:
		immobilienItem.setObjektNr(currentItem.getObjektNr());
		break;
	case YBD.Typ_ETAGE:
		immobilienItem.setEtageNr(currentItem.getEtageNr());
		break;
	case YBD.Typ_IMMOBILIE:
		immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
		break;
	case YBD.Typ_HAUS:
		immobilienItem.setHausNr(currentItem.getHausNr());
		break;
}

View Diff

1,14c1,16
< if (isTyp(YBD.Typ_GEBAEUDE, currentTyp)) {
< 	immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
< }
< if (isTyp(YBD.Typ_OBJEKT, currentTyp)) {
< 	immobilienItem.setObjektNr(currentItem.getObjektNr());
< }
< if (isTyp(YBD.Typ_ETAGE, currentTyp)) {
< 	immobilienItem.setEtageNr(currentItem.getEtageNr());
< }
< if (isTyp(YBD.Typ_IMMOBILIE, currentTyp)) {
< 	immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
< }
< if (isTyp(YBD.Typ_HAUS, currentTyp)) {
< 	immobilienItem.setHausNr(currentItem.getHausNr());
---
> switch (currentTyp) {
> 	case YBD.Typ_GEBAEUDE:
> 		immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
> 		break;
> 	case YBD.Typ_OBJEKT:
> 		immobilienItem.setObjektNr(currentItem.getObjektNr());
> 		break;
> 	case YBD.Typ_ETAGE:
> 		immobilienItem.setEtageNr(currentItem.getEtageNr());
> 		break;
> 	case YBD.Typ_IMMOBILIE:
> 		immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
> 		break;
> 	case YBD.Typ_HAUS:
> 		immobilienItem.setHausNr(currentItem.getHausNr());
> 		break;

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 31 remaining solutions by signing in and submitting your own entry
#32 Austin Ware / @AustinWare17 - Score: 113 - 03/13/18 @ 05:17
Oswitch (currentTyp) {<Esc>:%s/if (isTyp(/\tcase <CR>:%s/, currentTyp)) {/:<CR>:%s/}/\t\tbreak;<CR>kv>3k.3k>..3k.3k.Go}<Esc>v<<<ZZ

0 comments


Created by: @tannerli

32 active golfers, 91 entries

Leaderboard (lowest score wins):
92
#31 - Robert Siemieniec / @rsiemieniec

12/17/2014 at 10:17AM

113
#32 - Austin Ware / @AustinWare17

03/13/2018 at 05:17AM