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 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 38 remaining solutions by signing in and submitting your own entry
#39 Mattiassich Ákos / mattiassicha - Score: 142 - 01/04/11 @ 20:20
3jy2jGO<Esc>pVG:s/\vprivate (\w+) (\w+);/public \1 get\u\2() { return \2; }\r\tpublic void set\u\2( \1 ~2<BS><BS>\2 ) {\r\t\tthis.\2 = \2;\r\t}\r/<CR><CR>ddZZ

0 comments

#40 Alain Gilbert / alain_gilbert - Score: 143 - 01/05/11 @ 20: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

#41 Vernon Thommeret / synotic - Score: 144 - 01/30/11 @ 07: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

#42 Pete Johns / johnsyweb - Score: 148 - 01/04/11 @ 20: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

#43 sylwia / whaler - Score: 157 - 09/12/11 @ 17: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

#44 Christopher Brew / Seph1rothVII - Score: 158 - 01/12/12 @ 19: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

#45 Daniel Harrington / rubiii - Score: 160 - 12/11/11 @ 01: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

#46 Joost / vlabakje - Score: 248 - 02/21/11 @ 16: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

#47 Marcelo F Andrade / mfandrade - Score: 348 - 01/04/11 @ 19: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

#48 Mukhanov / Mukhanov - Score: 354 - 02/03/14 @ 08:04
3jyy3jO<CR><Tab><Esc>pkddcwpyb<BS><BS>ublic<Esc>wwiget<Esc>kjlrFA<BS>() { return firstName; }<CR><Esc>kyyjkpwcwviud<BS><BS>d<BS>od<BS><BS><BS>oid<Esc>wrswwwcwStri<BS><BS><BS><BS><Left><Left><Left><Left>S<BS> String firstName <Esc>llla<CR><Tab>i<BS>this.<Esc>A<Left><Left><Left>u<BS> = fri<BS><BS>is<BS>rstName<Esc>kjla<CR><BS><Esc>3k4yy3jjpffbbbblllcwSy<BS>urba<BS><BS>bane<BS><BS><BS><BS>name<Esc>wwwwcwsurbae<BS><BS><BS>name<Esc>hjb.jb.bbb.kbkhjllllcwSurbam<BS><BS><BS>name<Esc>k4yyjjjpO<Esc>jwcwInteger<Esc>jww.jkkbbblllcwAge<Esc>wwwwcwage<Esc>jhhh.jv<Esc>b.bbb.kcwAge<Esc>:wq<CR>

0 comments

Created by: krisajenkins

48 active golfers, 129 entries

Leaderboard (lowest score wins):
89
#1 - Petro Тrouq / zulolosi

01/03/2015 at 02:10PM

91
#2 - Urtica dioica / udioica

01/30/2013 at 01:08AM

91
#3 - John Braxler / braxler

12/22/2014 at 07:19PM

92
#4 - Wei Dai / clvv42

01/07/2011 at 02:21AM

92
#5 - ls lahrs / lslah

01/17/2011 at 04:35PM

92
#6 - You-Siang Lin / yslinnctu

12/05/2011 at 01:57PM

94
#7 - dominique pellé / vimgolfisto

01/05/2011 at 12:33AM

95
#8 - Nolen Royalty / NolenRoyalty

04/21/2012 at 09:43PM

96
#9 - Justin Love / wondible

08/17/2011 at 02:44AM

98
#10 - Saki Gw / Sakigw

06/18/2016 at 05:23PM

99
#11 - William Dunand / wdunand

11/17/2011 at 07:25AM

100
#12 - h_east (トロッコ6個) / h_east

01/04/2011 at 03:32PM

105
#13 - Matthew Draper / _matthewd

01/06/2011 at 05:44AM

106
#14 - Karel Vervaeke / karel1980

01/04/2011 at 02:12PM

106
#15 - Joonas Pihlajamaa / jokkebk

02/23/2014 at 09:02PM

108
#16 - Hu Junfeng / junfeng

07/27/2011 at 12:51PM

109
#17 - Douglas Stockwell / dstockwell

01/05/2011 at 02:21AM

110
#18 - hiding / I_haveno_name

11/14/2013 at 12:31AM

111
#19 - Tim Chase / gumnos

01/04/2011 at 11:19PM

112
#20 - Gael / darkael2

01/06/2011 at 07:18PM

113
#21 - Øystein Walle / oysteinwalle

07/08/2011 at 11:08PM

113
#22 - galadriel2143 / galadriel2143

07/05/2013 at 05:13AM

114
#23 - Glenn / spamcow_moo

01/04/2011 at 07:00PM

120
#24 - Renat Aksitov / Korvin79

01/29/2012 at 12:04PM

120
#25 - mwatkward / AftrschoolSpe

06/25/2012 at 10:06PM

121
#26 - Asmund Liseth / Asmund_L

01/04/2011 at 10:20PM

121
#27 - aimee / sermoa

01/08/2011 at 04:37PM

122
#28 - Mighty Byte / mightybyte

01/10/2011 at 10:30PM

123
#29 - timhoa / timhoa

01/23/2011 at 03:36PM

125
#30 - Ayose Cazorla / ayosec

09/03/2011 at 03:37PM

127
#31 - Mohammad-Javad Izadi / mjizadi

01/05/2011 at 12:56PM

127
#32 - Rob Ciaccio / RobertoCalavera

01/27/2011 at 12:00AM

129
#33 -  Ikhsan Maulana / ixandidu

01/07/2011 at 07:29PM

132
#34 - Eivind Jahren / HaskellElephant

01/18/2011 at 11:03PM

133
#35 - not so punk :] / notsopunk

06/19/2011 at 10:18AM

134
#36 - Piotr Śniegowski / PiotrSniegowski

06/06/2013 at 01:50PM

136
#37 - Francisco Dibar / frandibar

01/13/2011 at 08:10PM

138
#38 - drio / drio

01/16/2011 at 10:24PM

142
#39 - Mattiassich Ákos / mattiassicha

01/04/2011 at 08:20PM

143
#40 - Alain Gilbert / alain_gilbert

01/05/2011 at 08:58PM

144
#41 - Vernon Thommeret / synotic

01/30/2011 at 07:54AM

148
#42 - Pete Johns / johnsyweb

01/04/2011 at 08:16PM

157
#43 - sylwia / whaler

09/12/2011 at 05:45PM

158
#44 - Christopher Brew / Seph1rothVII

01/12/2012 at 07:49PM

160
#45 - Daniel Harrington / rubiii

12/11/2011 at 01:24AM

248
#46 - Joost / vlabakje

02/21/2011 at 04:53PM

348
#47 - Marcelo F Andrade / mfandrade

01/04/2011 at 07:34PM

354
#48 - Mukhanov / Mukhanov

02/03/2014 at 08:04AM