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 55213dc25709ea0851015904

Custom McCarthy sequence

Generate the first one hundred and twenty numbers (starting with n=1). See here for some inspiration: http://en.wikipedia.org/wiki/McCarthy_91_function

Start file
" Humm... :so%

"
Custom McCarthy 91 function
" M(n) = { n          if n > 97
"
       { M(M(n+1))  if n <= 97
function! Mc98(n)
 
if a:n > 97
   
return a:n
 
else
   
return Mc98(Mc98(a:n + 1))
  endif
endfunction

function! Mc98Line()
  let l
= getline('.')
  call setline
('.', Mc98(l))
endfunction

" Humm...
"
command! -range Mc98Cmd <line1>,<line2>call Mc98Line()
nmap M ciw
<C-R>=Mc98(<C-R>")<CR><Esc>
"
0put=range(1,120)
End file
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

View Diff

1,22c1,120
< " Humm... :so%
<
< "
Custom McCarthy 91 function
< " M(n) = { n          if n > 97
< "
       { M(M(n+1))  if n <= 97
< function! Mc98(n)
<   if a:n > 97
<     return a:n
<   else
<     return Mc98(Mc98(a:n + 1))
<   endif
< endfunction
<
< function! Mc98Line()
<   let l = getline('.')
<   call setline('.', Mc98(l))
< endfunction
<
< " Humm...
< "
command! -range Mc98Cmd <line1>,<line2>call Mc98Line()
< nmap M ciw<C-R>=Mc98(<C-R>")<CR><Esc>
< "
0put=range(1,120)
---
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 98
> 99
> 100
> 101
> 102
> 103
> 104
> 105
> 106
> 107
> 108
> 109
> 110
> 111
> 112
> 113
> 114
> 115
> 116
> 117
> 118
> 119
> 120

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 16 remaining solutions by signing in and submitting your own entry
#17 pftb12345 / @pftb12345 - Score: 28 - 04/05/15 @ 15:32
:so%<CR>GfrDVH"=<C-R>"<CR>pqqM+@qq@qZZ

0 comments


Created by: @mcr05

17 active golfers, 44 entries

Leaderboard (lowest score wins):
15
#1 - 杨洋 / @176795444

07/03/2017 at 07:45AM

15
#2 - Miłosz Łakomy / @foobar01123

12/30/2019 at 01:01PM

15
#3 - Peppa Pig / @PeppaPigSg

08/09/2024 at 12:17AM

16
#4 - John Braxler / @braxler

06/06/2017 at 03:11PM

17
#5 - Urtica dioica / @udioica

06/25/2015 at 07:44PM

17
#6 - Jon Krause / @jkrause314

01/18/2016 at 09:59PM

17
#7 - Saki Gw / @Sakigw

01/16/2020 at 03:26PM

17
#8 - nickGPT / @nickandbro

08/28/2024 at 04:17AM

19
#9 - Alex Bartol / @alexbartol

05/15/2015 at 02:30AM

19
#10 - Kaue Silveira / @kssilveira

11/26/2015 at 12:46AM

19
#11 - Olivier Bégassat / @zk_evm

06/15/2023 at 11:12AM

20
#12 - Tim Chase / @gumnos

04/05/2015 at 06:48PM

20
#13 - Petro Тrouq / @zulolosi

04/09/2015 at 10:17PM

20
#14 - Marco Meinardi / @Kee__no

01/10/2023 at 07:24PM

24
#15 - E Both / @enboth

04/06/2015 at 08:55PM

25
#16 - Alex / @AlexanderHeatl2

07/07/2022 at 10:25PM

28
#17 - pftb12345 / @pftb12345

04/05/2015 at 03:32PM