Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Leaderboard, Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 4d22dcfa7f75b01e0700010e

Getters & Setters: Java

Boilerplate getters & setters - it's a tedious fact of life in Java, and probably the only thing that still pulls me back to an IDE. Perhaps someone knows a fast, pure vim way...

Start file
package com.vimgolf.challenge;

public class Person {
	private String firstName;
	private String surname;
	private Integer age;
}
End file
package com.vimgolf.challenge;

public class Person {
	private String firstName;
	private String surname;
	private Integer age;

	public String getFirstName() { return firstName; }
	public void setFirstName( String firstName ) {
		this.firstName = firstName;
	}

	public String getSurname() { return surname; }
	public void setSurname( String surname ) {
		this.surname = surname;
	}

	public Integer getAge() { return age; }
	public void setAge( Integer age ) {
		this.age = age;
	}
}

View Diff

6a7,21
> 
> 	public String getFirstName() { return firstName; }
> 	public void setFirstName( String firstName ) {
> 		this.firstName = firstName;
> 	}
> 
> 	public String getSurname() { return surname; }
> 	public void setSurname( String surname ) {
> 		this.surname = surname;
> 	}
> 
> 	public Integer getAge() { return age; }
> 	public void setAge( Integer age ) {
> 		this.age = age;
> 	}

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 32 remaining solutions by signing in and submitting your own entry
#33 Alain Gilbert / @alain_gilbert - Score: 143 - 01/05/11 @ 12:58
3jy2jGO<Esc>pVG:s/\vprivate (\w+) (\w+);/public \1 get\u\2() { return \2; }\r\tpublic void set <BS>\u\2( \1 ~2<BS><BS>\2 ) {\r\t\tthis.\2 = \2;\r\t}\r/<CR>ddZZ

0 comments

#34 Vernon Thommeret / @synotic - Score: 144 - 01/29/11 @ 23:54
<Down><Down><Down>qqyyGO<Esc>pciwpublic<Esc>yy2pj2wd^i<Tab>this.<Esc>wye$i = <Esc>po<BS>}<Esc>2kwciwvoid<Esc>wyeiset<Esc>l~$a<BS>( <Esc>pa ) {<Esc>kbbyej$bbPa <Esc>kbyeiget<Esc>l~$i() { return <Esc>pa<Right> }<Esc>q<Up><Up><Up>@q:6<CR>@qZZ

0 comments

#35 Pete Johns / @johnsyweb - Score: 148 - 01/04/11 @ 12:16
4GqqYGO<Esc>p:s!\v.*( \i+ )(\i+);!public\1get\u\2() { return \2; }<CR>p:s!\v.*( \i+ )(\i+);!public void set\u\2(\1\2 ) {<C-V><CR>this.\2 = \2;<C-V><CR>}<CR>q5G@q66G@q==ggZZ

@johnsyweb: Why use an IDE, Kris? I'd take a plug-in approach: https://github.com/johnsyweb/dotfiles/blob/master/.vim/ftplugin/java.vim

1 comment

#36 sylwia / @whaler - Score: 157 - 09/12/11 @ 10:45
3jqqyyGO<Esc>p<Esc>yy2pj2wd^i<Tab>this.<Esc>wye$i = <Esc>po<BS>}<Esc>2kwciwvoid<Esc>wyeiset<Esc>l~$a<BS>( <Esc>pa ) {<Esc>kbbyej$bbPa <Esc>kbyeiget<Esc>l~$i() { return <Esc>pa<Right> }<Esc>q3<Up>@q:6<CR>@q<Esc>:8,$s/private/public/g<CR>ZZ

0 comments

#37 Christopher Brew / @Seph1rothVII - Score: 158 - 01/12/12 @ 11:49
:%s/^\s*private \(\a*\) \(\a*\);$/&\r\tpublic \1 get\u\2() { return \2; }\r\tpublic void set\u\2( \1 \2 ) {\r\t\tthis.\2 = \2;\r\t}\r/g<CR>dd4Gp17Gdd4Gp7jdd4GpZZ

0 comments

#38 Daniel Harrington / @rubiii - Score: 160 - 12/10/11 @ 17:24
4Gqq2wywGO<CR><Tab>public String get<Esc>pb3l~A() { return <Esc>pa; }<CR>public void set<Esc>pb3l~A()<BS> String <Esc>pA ) {<CR><Tab>this.<Esc>pa = <Esc>pa;<CR>}<Left><BS><Esc>q5G1@q6G1@qjjkkk:s/String/Integer<CR>k.u:<Up><CR>:x<CR>

0 comments

#39 Joost / @vlabakje - Score: 248 - 02/21/11 @ 08:53
Gko<CR>pu<C-N> S<C-N> getFirstName() { return f<C-N>; }<CR>pu<C-N> void setFirstName( S<C-N> f<C-N> ) {<CR><Tab>this.f<C-N> = f<C-N>;<CR><BS>}<CR><CR>pu<C-N> S<C-N> getSurname() { r<C-N> s<C-N><C-N>; }<CR>pu<C-N> v<C-N><C-N> setSurname( S<C-N> su<C-N> ) {<CR><Tab>t<C-N>.su<C-N> = su<C-N>;<CR><BS>}<CR><CR>pu<C-N> I<C-N> getAge() { r<C-N> a<C-N>; }<CR>pu<C-N> vo<C-N> setAge()<BS> I<C-N> a<C-N> ) {<CR><Tab>t<C-N>.a<C-N> = a<C-N>;<CR><BS>}<Esc>ZZ

0 comments

#40 Marcelo F Andrade / @mfandrade - Score: 348 - 01/04/11 @ 11:34
GO<CR><Tab>public String getFirstName() { return firstName; }<Esc>opublic void setFirstName()<BS> String firstName ) {}<Left><CR><Esc>O<Tab>this.firstName = firsn<BS>tName;<Esc><Up><Up>04Yo<Esc>u<Down><Down><Down><Down>O<Esc>pGO<Esc>p<Esc><Up><Up><Up><Up><Up>3!!sed s/firstName/surname/g<CR>:<Up><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><End><Left><Right>i<CR><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Left>~<Right><Right><Right><Right><Right><Right><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Down><Left><Right><Right>~<Esc>18G3!!<Up><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Right><Del><Del><Del><Del><Del><Del><Del><Del>age/<CR><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right>~<Down><Left><Left><Left>~<Right><Right><Right><Right><Right><Left>dwiInteger <Esc><Up>bbbbbcwInteger<Esc>:x<CR>

0 comments

Created by: @krisajenkins

40 active golfers, 102 entries

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

01/29/2013 at 05:08PM

Me-small_normal
92
#2 - Wei Dai / @clvv42

01/06/2011 at 06:21PM

Fotos-0259_normal
92
#3 - ls lahrs / @lslah

01/17/2011 at 08:35AM

Gintoki_normal
92
#4 - You-Siang Lin / @yslinnctu

12/05/2011 at 05:57AM

Dom-50_normal
94
#5 - dominique pellé / @vimgolfisto

01/04/2011 at 04:33PM

264327_10150230576896345_729061344_7523848_5517118_n_normal
95
#6 - Nolen Royalty / @NolenRoyalty

04/21/2012 at 02:43PM

Jlove201003sq_normal
96
#7 - Justin Love / @wondible

08/16/2011 at 07:44PM

Default_profile_6_normal
99
#8 - William Dunand / @wdunand

11/16/2011 at 11:25PM

P1000007_normal
100
#9 - h_east (DDD ready) / @h_east

01/04/2011 at 07:32AM

E55df1cc7d5fdb4ae9bc2afcb9afe7e4_normal
105
#10 - matthewd / @_matthewd

01/05/2011 at 09:44PM

Default_profile_5_normal
106
#11 - Karel Vervaeke / @karel1980

01/04/2011 at 06:12AM

Avatar-small_normal
108
#12 - Hu Junfeng / @hujunfeng

07/27/2011 at 05:51AM

Shiraseon3_normal
109
#13 - Douglas Stockwell / @dstockwell

01/04/2011 at 06:21PM

T_e_normal
111
#14 - Tim Chase / @gumnos

01/04/2011 at 03:19PM

Default_profile_5_normal
112
#15 - Gael / @darkael2

01/06/2011 at 11:18AM

Avatar_normal
113
#16 - Øystein Walle / @oysteinwalle

07/08/2011 at 04:08PM

Hrleft_normal
114
#17 - Glenn / @spamcow_moo

01/04/2011 at 11:00AM

Default_profile_2_normal
120
#18 - Renat Aksitov / @Korvin79

01/29/2012 at 04:04AM

Wombat-large_normal
120
#19 - mwatkward / @AftrschoolSpe

06/25/2012 at 03:06PM

Gravatar_normal
121
#20 - Asmund Liseth / @Asmund_L

01/04/2011 at 02:20PM

45072b62-96bd-47e0-bb3a-83ec72a6e2af_normal
121
#21 - aimee / @sermoa

01/08/2011 at 08:37AM

Default_profile_4_normal
122
#22 - Mighty Byte / @mightybyte

01/10/2011 at 02:30PM

Default_profile_0_normal
123
#23 - timhoa / @timhoa

01/23/2011 at 07:36AM

T_normal
125
#24 - Ayose Cazorla / @ayosec

09/03/2011 at 08:37AM

Final_normal
127
#25 - Mohammad-Javad Izadi / @mjizadi

01/05/2011 at 04:56AM

1309650785306_normal
127
#26 - Rob Ciaccio / @RobertoCalavera

01/26/2011 at 04:00PM

Untitled_2_normal
129
#27 -  Ikhsan Maulana / @ixandidu

01/07/2011 at 11:29AM

Dude2_normal
132
#28 - Eivind Jahren / @HaskellElephant

01/18/2011 at 03:03PM

122_normal
133
#29 - not so punk :] / @notsopunk

06/19/2011 at 03:18AM

Default_profile_6_normal
136
#30 - Francisco Dibar / @frandibar

01/13/2011 at 12:10PM

29ed1f20888463b3b72bd9fed88a79b8_normal
138
#31 - drio / @drio

01/16/2011 at 02:24PM

Default_profile_0_normal
142
#32 - Mattiassich Ákos / @mattiassicha

01/04/2011 at 12:20PM

6240_139454607906_723872906_3271730_5845230_n_normal
143
#33 - Alain Gilbert / @alain_gilbert

01/05/2011 at 12:58PM

Vernon_normal
144
#34 - Vernon Thommeret / @synotic

01/29/2011 at 11:54PM

Image_normal
148
#35 - Pete Johns / @johnsyweb

01/04/2011 at 12:16PM

Lole_normal
157
#36 - sylwia / @whaler

09/12/2011 at 10:45AM

Image1326661166_normal
158
#37 - Christopher Brew / @Seph1rothVII

01/12/2012 at 11:49AM

Avatar_normal
160
#38 - Daniel Harrington / @rubiii

12/10/2011 at 05:24PM

Foto_joost_normal
248
#39 - Joost / @vlabakje

02/21/2011 at 08:53AM

42e1048f-65f1-4f3f-b450-0bcff11b1c26_normal
348
#40 - Marcelo F Andrade / @mfandrade

01/04/2011 at 11:34AM