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 36 remaining solutions by signing in and submitting your own entry
#37 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

37 active golfers, 105 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

27
#3 - Jean George / @JeanGeo20504212

10/22/2023 at 10:49PM

27
#4 - Peppa Pig / @PeppaPigSg

07/02/2024 at 06:18AM

28
#5 - Petro Тrouq / @zulolosi

07/23/2020 at 05:50PM

28
#6 - Tanzeel Kazi / @tanzeelkazi

08/18/2020 at 05:26PM

30
#7 - Filipe Brandenburger / @filbranden

11/16/2020 at 10:36PM

30
#8 - mevmev / @mevmev8

09/15/2021 at 02:28PM

30
#9 - Alex / @AlexanderHeatl2

08/29/2022 at 09:45PM

30
#10 - Lithrein / @Lithrein

10/01/2023 at 08:46AM

31
#11 - Saki Gw / @Sakigw

07/20/2020 at 07:29AM

31
#12 - "Smylers" / @Smylers2

07/27/2020 at 05:59AM

32
#13 - PK / @pkeugine

07/20/2020 at 03:38AM

33
#14 - garry quested / @GQuested

07/20/2020 at 04:39PM

33
#15 - せいほう / @FICSQF

07/23/2020 at 12:31PM

33
#16 - Jung Yeon Park / @park_jungy

02/14/2021 at 08:10PM

33
#17 - Max Mossberg / @mxmossy

06/30/2021 at 06:39PM

33
#18 - wpr__ / @wpr____

12/11/2021 at 01:29PM

34
#19 - ShookerAndBeta / @Shooker2012

11/15/2022 at 01:00PM

35
#20 - Matt / @mcr05

07/19/2020 at 11:34AM

36
#21 - Norbert / @mullno

07/18/2020 at 08:04PM

36
#22 - Dan / @dstein64

07/18/2020 at 10:35PM

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

06/12/2022 at 03:09PM

38
#24 - mike-vimgolf / @MVimgolf

12/29/2020 at 12:28AM

38
#25 - Luoyb / @Luoyb

10/26/2023 at 01:44AM

39
#26 - Juan Manuel Fresia / @fresiajm

08/18/2020 at 12:27AM

40
#27 - Seve / @Seve_py

07/21/2020 at 02:19PM

40
#28 - Martin Kauppinen / @MartinKauppinen

08/16/2020 at 03:32PM

40
#29 - Martin Bielik / @mabielik

08/30/2020 at 03:20PM

42
#30 - analogpixel / @analogp1xel

07/19/2020 at 08:34PM