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 4e7dedb4f447090001000002

Refactor to Helpers

This Rails partial is almost all template escapes. Put it into a helper, and refactor each case to methods so we can build out the controls for each. (I've converted to tabs - fighting with Vimgolf's default config shouldn't be part of the challenge.)

Start file
## _controls.html.erb
<div class='controls'>
	<% if event.author == current_user -%>
		<%= link_to "Edit Activity", edit_event_path(event), :class => 'button' %>
	<% else -%>
		<% if current_user.attending? event -%>
			<%= link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post %>
		<% else -%>
			<% if current_user.invited_to? event -%>
				<%= link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post %>
			<% else -%>
				<%= link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post %>
			<% end -%>
		<% end -%>
	<% end -%>
</div>

## event_helper.rb
module EventHelper
end
End file
## _controls.html.erb
<div class='controls'>
	<%= event_controls event %>
</div>

## event_helper.rb
module EventHelper
	def event_controls(event)
		if event.author == current_user
			author_controls(event)
		elsif current_user.attending? event
			attendee_controls(event)
		elsif current_user.invited_to? event
			invitee_controls(event)
		else
			public_controls(event)
		end
	end

	def author_controls(event)
		link_to "Edit Activity", edit_event_path(event), :class => 'button'
	end

	def attendee_controls(event)
		link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post
	end

	def invitee_controls(event)
		link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post
	end

	def public_controls(event)
		link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post
	end
end

View Diff

3,15c3
< 	<% if event.author == current_user -%>
< 		<%= link_to "Edit Activity", edit_event_path(event), :class => 'button' %>
< 	<% else -%>
< 		<% if current_user.attending? event -%>
< 			<%= link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post %>
< 		<% else -%>
< 			<% if current_user.invited_to? event -%>
< 				<%= link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post %>
< 			<% else -%>
< 				<%= link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post %>
< 			<% end -%>
< 		<% end -%>
< 	<% end -%>
---
> 	<%= event_controls event %>
19a8,34
> 	def event_controls(event)
> 		if event.author == current_user
> 			author_controls(event)
> 		elsif current_user.attending? event
> 			attendee_controls(event)
> 		elsif current_user.invited_to? event
> 			invitee_controls(event)
> 		else
> 			public_controls(event)
> 		end
> 	end
> 
> 	def author_controls(event)
> 		link_to "Edit Activity", edit_event_path(event), :class => 'button'
> 	end
> 
> 	def attendee_controls(event)
> 		link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post
> 	end
> 
> 	def invitee_controls(event)
> 		link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post
> 	end
> 
> 	def public_controls(event)
> 		link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post
> 	end

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 9 remaining solutions by signing in and submitting your own entry
#10 You-Siang Lin / @yslinnctu - Score: 423 - 12/14/11 @ 16:58
/ -\?%><CR>g&/<%=\? <CR>g&3GO<% <BS>= e<C-N> _<C-N><Esc>bXA e<C-N> %><Esc>17GdG<C-O>3Gp4jddidef e<C-P><C-P><C-P><C-P>(e<C-N>)<CR><Up><Tab><Down><kHome><Tab><Tab><kEnd><CR><Tab>au<C-P>_controls(e<C-N><C-N><C-N>)<Esc>jddGpi<CR><Up><kEnd><kHome><kEnd><Esc><kHome><Right><Left><Right><Down><Up><Left><Down><Up><Left><Left><Down><Up>dd<Up>o<Down>def au<C-P>(ev<C-N>)<CR><Tab><kEnd><CR><BS>end<Esc><C-O>ddiels<Esc>o<Tab>attendee _co<C-P><Esc>bX$a(ev<C-N>)<Esc>jddGo<CR>def att<C-P>(ev<C-N>)<BS><BS><BS><BS><BS><BS><BS><BS><BS><BS>)<CR><Esc>pXkddo<BS>end<Esc><C-O>ddXiels<Esc>jxd<Esc>ddGo<CR>def invitee_<BS> _con<C-P><Esc>bXA(ev<C-N><C-N>)<CR><Esc>puuuuui<Up><kEnd><CR><Up><BS><kEnd><Down><kEnd><Tab><Tab><Tab>invitee_controls(ev<C-N>)<Esc>jddGo<CR>def iv<BS>nv<C-P>(ev<C-N><C-N>)<CR><Esc>pXkddo<BS>end<Esc><C-O>i<BS><kEnd><Down><kHome><Del><Esc>ddGo<CR>def public_controls(ev<C-N><C-N>)<CR><Esc>pXkddo<BS>end<CR><BS>end<Esc><C-O>cwpu<C-P>(ev<C-N>)<Esc>ZZ

0 comments

#11 Rob C. Grant / @rob_c_grant - Score: 484 - 02/01/12 @ 10:39
jjV12jd:6<CR>o<Tab>def event_controls(event)<Esc>pV12j:s/<\%=? //<CR><CR>:qq!<BS><BS><Esc><Esc>/<%=?<BS><BS>=\? <BS><CR>nnn/ -\?%><CR>kkkkVjjjjjjjjjjjjj:s/<%=\? \| -\?%>//<CR>uVjjjjjjjjjjjj:s<Up>g<CR>o<CR>end<Esc>kdd=ggujV12j>:21<CR>:10<CR>JXxjj<<JXxjj<<<<jj<<<<jdjo<CR>def author_controls<CR>end<CR><CR>def attendee_controls<Esc>kkkA(event)<Esc>:22<CR>.oend<CR><CR>def invitee_C<BS>controls(event)<CR>end<CR><CR>def public_controls(event)<CR>end<Esc>:9<CR>dd:18<CR>p<<.u:8<CR>oau<C-N>(e<C-N><C-N>)>><BS><BS><BS>)>><BS><BS><Esc>>>jjcc<Tab>atte<C-N>(event)<Esc>:23<CR>p<<.:13<CR>ccinv<C-N>(e<C-P>)<Esc>>>:27<CR>p<<..:15<CR>cc<Tab>pub<C-N>(event)<Esc>:31<CR>p<<..:2<CR>o<5<BS>%= eve<C-N><C-N><C-N> event %><Esc>:<Esc>ZZ

0 comments

#12 Pasha Klets / @p01nt - Score: 855 - 10/27/11 @ 14:47
jdG:se paste<CR>o<div class='controls'><CR><Tab><%= event_controls event %><CR></div><CR><CR>## event_helper.rb<CR>module EventHelper<CR><Tab>def event_controls(event)<CR><Tab><Tab>if event.author == current_user<CR><Tab><Tab><Tab>author_controls(event)<CR><Tab><Tab>elsif current_user.attending? event<CR><Tab><Tab><Tab>attendee_controls(event)<CR><Tab><Tab>elsif current_user.invited_to? event<CR><Tab><Tab><Tab>invitee_controls(event)<CR><Tab><Tab>else<CR><Tab><Tab><Tab>public_controls(event)<CR><Tab><Tab>end<CR><Tab>end<CR><CR><Tab>def author_controls(event)<CR><Tab><Tab>link_to "Edit Activity", edit_event_path(event), :class => 'button'<CR><Tab>end<CR><CR><Tab>def attendee_controls(event)<CR><Tab><Tab>link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post<CR><Tab>end<CR><CR><Tab>def invitee_controls(event)<CR><Tab><Tab>link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post<CR><Tab>end<CR><CR><Tab>def public_controls(event)<CR><Tab><Tab>link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post<CR><Tab>end<CR>end<Esc>ZZ

0 comments

Created by: @wondible

12 active golfers, 18 entries

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

08/01/2012 at 11:05PM

Jlove201003sq_normal
148
#2 - Justin Love / @wondible

12/23/2011 at 08:45PM

Default_profile_1_normal
158
#3 - John Anderson / @opejn

12/24/2011 at 11:53PM

P1000007_normal
171
#4 - h_east (DDD ready) / @h_east

10/01/2011 at 10:49PM

Abdel_normal
176
#5 - Abdel Said / @abdelsaid

02/17/2012 at 07:02AM

Default_profile_6_normal
210
#6 - William Dunand / @wdunand

02/27/2012 at 10:29PM

Av_normal
286
#7 - Vasil Sakarov / @vsakarov

12/28/2011 at 03:38AM

Photo_4_normal
288
#8 - maxthoursie / @maxthoursie

01/31/2012 at 12:49AM

E269db141731bb4b5dd8d6c1288d39c7_normal
352
#9 - Jonathan Lozinski / @jlozinski

04/21/2012 at 11:07AM

Gintoki_normal
423
#10 - You-Siang Lin / @yslinnctu

12/14/2011 at 04:58PM

Photo_on_2010-06-29_at_23.03_normal
484
#11 - Rob C. Grant / @rob_c_grant

02/01/2012 at 10:39AM

L3mo9g2d3jpj7ysqb4iz_normal
855
#12 - Pasha Klets / @p01nt

10/27/2011 at 02:47PM