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 5f1310bd3cc9f3000bef87ed

Levenshtein distance

Compute distance for each pair. Notice that this recursive implementation is very inefficient. Wagner-Fischer algorithm is iterative and much faster. #vimscript

Start file
" Levenshtein distance between two strings
function! LD(s1, s2)
  let l1 = strlen(a:s1)
  let l2 = strlen(a:s2)
  if l1 <= 0
    return l2
  elseif l2 <= 0
    return l1
  elseif a:s1[0] ==# a:s2[0]
    return LD(a:s1[1:], a:s2[1:])
  else
    return 1 + min([
    \ LD(a:s1, a:s2[1:]), LD(a:s1[1:], a:s2), LD(a:s1[1:], a:s2[1:])
    \ ])
  endif
endfunction
" Humm... Is this useful?
"nmap M I<C-R>=LD("<C-R>a","<C-R>b")<CR><Esc>

"VIM VimGolf
"keystroke matt
"vimscript way
"reformat refactor
"challenge chatter
"colons semicolons
"golfer golfers
"order sorting
"modules models
"shift+ret ctrl+ret
"ninja manic
"destination distance
"pattern lines
"linewrapping linewrapping
"swap switch
"vice versa
"split multiples
"block blackened
"-a-b-c c-a-b
"hello_world hello world!
End file
6
8
9
5
5
4
1
5
2
5
4
7
6
0
4
4
7
5
3
2

View Diff

1,39c1,20
< " Levenshtein distance between two strings
< function! LD(s1, s2)
<   let l1 = strlen(a:s1)
<   let l2 = strlen(a:s2)
<   if l1 <= 0
<     return l2
<   elseif l2 <= 0
<     return l1
<   elseif a:s1[0] ==# a:s2[0]
<     return LD(a:s1[1:], a:s2[1:])
<   else
<     return 1 + min([
<     \ LD(a:s1, a:s2[1:]), LD(a:s1[1:], a:s2), LD(a:s1[1:], a:s2[1:])
<     \ ])
<   endif
< endfunction
< " Humm... Is this useful?
< "nmap M I<C-R>=LD("<C-R>a","<C-R>b")<CR><Esc>
< 
< "VIM VimGolf
< "keystroke matt
< "vimscript way
< "reformat refactor
< "challenge chatter
< "colons semicolons
< "golfer golfers
< "order sorting
< "modules models
< "shift+ret ctrl+ret
< "ninja manic
< "destination distance
< "pattern lines
< "linewrapping linewrapping
< "swap switch
< "vice versa
< "split multiples
< "block blackened
< "-a-b-c c-a-b
< "hello_world hello world!
---
> 6
> 8
> 9
> 5
> 5
> 4
> 1
> 5
> 2
> 5
> 4
> 7
> 6
> 0
> 4
> 4
> 7
> 5
> 3
> 2

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 31 remaining solutions by signing in and submitting your own entry
#32 Rennnda / @rennnda2020 - Score: 48 - 04/27/21 @ 14:36
cG6<CR>8<CR>9<CR>5<CR>5<CR>4<CR>1<CR>5<CR>2<CR>5<CR>4<CR>7<CR>6<CR><CR><BS>0<CR>4<CR>4<CR>7<CR>5<CR>3<CR>2<CR><BS><Esc>ZZ

0 comments


Created by: @mcr05

32 active golfers, 92 entries

Leaderboard (lowest score wins):
27
#1 - jinx balotchnik / @balotchnik

07/23/2023 at 12:27AM

27
#2 - John Braxler / @braxler

09/08/2023 at 02:52PM

28
#3 - Petro Тrouq / @zulolosi

07/23/2020 at 05:50PM

28
#4 - Tanzeel Kazi / @tanzeelkazi

08/18/2020 at 05:26PM

30
#5 - Filipe Brandenburger / @filbranden

11/16/2020 at 10:36PM

30
#6 - mevmev / @mevmev8

09/15/2021 at 02:28PM

30
#7 - Alex / @AlexanderHeatl2

08/29/2022 at 09:45PM

31
#8 - Saki Gw / @Sakigw

07/20/2020 at 07:29AM

31
#9 - Smylers / @Smylers2

07/27/2020 at 05:59AM

32
#10 - PK / @pkeugine

07/20/2020 at 03:38AM

33
#11 - garry quested / @GQuested

07/20/2020 at 04:39PM

33
#12 - せいほう / @FICSQF

07/23/2020 at 12:31PM

33
#13 - Jung Yeon Park / @park_jungy

02/14/2021 at 08:10PM

33
#14 - Max Mossberg / @mxmossy

06/30/2021 at 06:39PM

33
#15 - wpr__ / @wpr____

12/11/2021 at 01:29PM

34
#16 - ShookerAndBeta / @Shooker2012

11/15/2022 at 01:00PM

35
#17 - Matt / @mcr05

07/19/2020 at 11:34AM

36
#18 - Norbert / @mullno

07/18/2020 at 08:04PM

36
#19 - Dan / @dstein64

07/18/2020 at 10:35PM

37
#20 - math is what I hate / @mpnmbn

06/12/2022 at 03:09PM

38
#21 - mike-vimgolf / @MVimgolf

12/29/2020 at 12:28AM

39
#22 - Juan Manuel Fresia / @fresiajm

08/18/2020 at 12:27AM

40
#23 - Seve / @Seve_py

07/21/2020 at 02:19PM

40
#24 - Martin Kauppinen / @MartinKauppinen

08/16/2020 at 03:32PM

40
#25 - Martin Bielik / @mabielik

08/30/2020 at 03:20PM

42
#26 - analogpixel / @analogp1xel

07/19/2020 at 08:34PM

44
#27 - Jason / @jason_eveleth

07/23/2020 at 06:58AM

44
#28 - Borna Sadeghi / @borna_sadeghi

03/19/2021 at 07:28PM

44
#29 - chriskuck / @chriskuck

03/25/2021 at 03:34PM

44
#30 - Marco Meinardi / @chino_meinardi

12/30/2022 at 08:53PM