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 22 remaining solutions by signing in and submitting your own entry
#23 Ram Tamtam / ramtamtamtam - Score: 71 - 12/17/14 @ 09:23
Oswitch (c<C-N>) {<Esc>:%s/if (isTyp(/case <CR>:%s/,.*/:<CR>:%s/}/<Tab>break;<CR>o}<Esc><<k>i{ZZ

0 comments

#24 Geoff Huston / AGeoffHuston - Score: 77 - 12/23/14 @ 03:54
Oswitch (c<C-N>) {<Esc>:g/if/norm ctY<Tab>case <C-V><Esc>t,lC:<CR>:g/\Cim/><CR>:%s/}/<C-V><Tab><C-V><Tab>break;<CR>o<BS><BS>}<Esc>ZZ

0 comments

#25 Ed / posva - Score: 78 - 12/17/14 @ 16:40
Oswitch () {<Esc>jWywkbpjFYqwyt,o<Tab>case :<Esc>Pkddj>>obreak;<Esc>jjFYq4@w4kdd4kdd4kdd4kddZZ

0 comments

#26 luffy / raxcoi - Score: 79 - 12/17/14 @ 08:39
Oswitch (currentTyp) {<Esc>j0qqc2f(case <Esc>f,c$:<Down><Down><BS><Tab>ca<BS><BS>break;<Esc>0<C-V>kkI<Tab><Esc>jjj0q4@qo<BS><BS>}<Esc>ZZ

0 comments

#27 Raynard, Jordan / raynard_jordan - Score: 83 - 01/14/15 @ 15:15
Oswitch (c<C-N>) {<Esc>jFYvtGy:%s/.*\(<C-R>".*\),.*/<Tab>case \1:<CR>:%s/<Tab>i/<Tab><Tab>i<CR>:%s/}/<Tab><Tab>break;<CR>o}<Esc>==ZZ

0 comments

#28 Robert Siemieniec / rsiemieniec - Score: 92 - 12/17/14 @ 10:17
Oswitch (c<C-N>) {<Esc>:%s:.*\(YBD\.\w*\).*:\tcase \1\::g<CR>:%s:}:\t\tbreak;:g<CR>o<BS><BS>}<Esc>:%s:\ti:\t\ti:g<CR>ZZ

0 comments

Created by: tannerli

28 active golfers, 72 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

48
#5 - YAMADA Yukimi / edp02

12/21/2014 at 06:24AM

49
#6 - Josu Oyanguren / josuoyanguren

12/17/2014 at 03:32PM

50
#7 - Matthieu Crapet / mcr05

01/11/2015 at 08:45PM

52
#8 - Michi Loro / michiloro

12/18/2014 at 01:04PM

52
#9 - Håken Lid / haakenlid

01/19/2015 at 11:28AM

53
#10 - Carlos A Henríquez Q / lagunex

01/16/2015 at 06:23PM

54
#11 - mnx / mnxx

12/17/2014 at 11:06AM

56
#12 - r. / rmarvie

12/19/2014 at 08:17AM

56
#13 - Dane Summers / dsummersl

12/19/2014 at 03:12PM

57
#14 - Carlos López / morrizon

12/21/2014 at 08:18PM

58
#15 - adi li / guessimtoolate

12/21/2014 at 07:08PM

60
#16 - ltn614 / ltn614

09/28/2015 at 01:22PM

61
#17 - Elizabeth / sprinkles418

12/17/2014 at 06:36PM

62
#18 - david hu / chin33z

12/17/2014 at 09:10AM

64
#19 - Poigal Nitish / poigalnitish

12/24/2014 at 08:11PM

65
#20 - Gabor Lekeny / leki75

12/21/2014 at 06:57PM

67
#21 - Karun Ramakrishnan / the_karun

12/19/2014 at 06:23PM

69
#22 - xieyh11 / xieyh11

02/28/2015 at 09:10AM

71
#23 - Ram Tamtam / ramtamtamtam

12/17/2014 at 09:23AM

77
#24 - Geoff Huston / AGeoffHuston

12/23/2014 at 03:54AM

78
#25 - Ed / posva

12/17/2014 at 04:40PM

79
#26 - luffy / raxcoi

12/17/2014 at 08:39AM

83
#27 - Raynard, Jordan / raynard_jordan

01/14/2015 at 03:15PM

92
#28 - Robert Siemieniec / rsiemieniec

12/17/2014 at 10:17AM