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

34 active golfers, 116 entries

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

12/17/2014 at 11:12AM

47
#2 - John Braxler / @braxler

12/17/2014 at 10:57PM

47
#3 - Kentaro Wakayama / @wakayamakentaro

12/17/2014 at 11:22PM

47
#4 - Petro Тrouq / @zulolosi

12/19/2014 at 07:19PM

47
#5 - Arya Kumar / @SusSquirrel

05/21/2021 at 04:36PM

47
#6 - Peppa Pig / @PeppaPigSg

07/03/2024 at 03:09AM

47
#7 - nickGPT / @nickandbro

08/28/2024 at 04:46AM

48
#8 - ゆきみ / @edp02

12/21/2014 at 06:24AM

49
#9 - Josu Oyanguren / @josuoyanguren

12/17/2014 at 03:32PM

50
#10 - Matt / @mcr05

01/11/2015 at 08:45PM

52
#11 - Michi Loro / @michiloro

12/18/2014 at 01:04PM

52
#12 - Håken Lid / @haakenlid

01/19/2015 at 11:28AM

53
#13 - Carlos A Henríquez Q / @lagunex

01/16/2015 at 06:23PM

54
#14 - mnx / @mnxx

12/17/2014 at 11:06AM

56
#15 - r. / @rmarvie

12/19/2014 at 08:17AM

56
#16 - Dane Summers / @dsummersl

12/19/2014 at 03:12PM

57
#17 - Carlos López / @morrizon

12/21/2014 at 08:18PM

58
#18 - adi li / @guessimtoolate

12/21/2014 at 07:08PM

60
#19 - ltn614 / @ltn614

09/28/2015 at 01:22PM

60
#20 - Alex / @AlexanderHeatl2

07/08/2022 at 08:23PM

61
#21 - Elizabeth / @sprinkles418

12/17/2014 at 06:36PM

61
#22 - Marc Päpper / @mpaepper

01/28/2019 at 03:45PM

62
#23 - david hu / @chin33z

12/17/2014 at 09:10AM

64
#24 - Poigal Nitish / @poigalnitish

12/24/2014 at 08:11PM

65
#25 - Gabor Lekeny / @leki75

12/21/2014 at 06:57PM

67
#26 - Karun Ramakrishnan / @the_karun

12/19/2014 at 06:23PM

69
#27 - xieyh11 / @xieyh11

02/28/2015 at 09:10AM

71
#28 - Ram Tamtam / @ramtamtamtam

12/17/2014 at 09:23AM

77
#29 - Geoff Huston / @AGeoffHuston

12/23/2014 at 03:54AM

78
#30 - Ed / @posva

12/17/2014 at 04:40PM