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

23 active golfers, 62 entries

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

07/23/2020 at 05:50PM

28
#2 - Tanzeel Kazi / @tanzeelkazi

08/18/2020 at 05:26PM

28
#3 - John Braxler / @braxler

01/28/2021 at 07:33PM

30
#4 - Filipe Brandenburger / @filbranden

11/16/2020 at 10:36PM

31
#5 - Saki Gw / @Sakigw

07/20/2020 at 07:29AM

31
#6 - Smylers / @Smylers2

07/27/2020 at 05:59AM

32
#7 - PK / @pkeugine

07/20/2020 at 03:38AM

33
#8 - garry quested / @GQuested

07/20/2020 at 04:39PM

33
#9 - せいほう / @FICSQF

07/23/2020 at 12:31PM

33
#10 - Jung Yeon Park / @park_jungy

02/14/2021 at 08:10PM

35
#11 - Matt / @mcr05

07/19/2020 at 11:34AM

36
#12 - Norbert / @mullno

07/18/2020 at 08:04PM

36
#13 - Daniel Steinberg / @dstein64

07/18/2020 at 10:35PM

38
#14 - mike-vimgolf / @MVimgolf

12/29/2020 at 12:28AM

39
#15 - Juan Manuel Fresia / @fresiajm

08/18/2020 at 12:27AM

40
#16 - Seve / @Seve_py

07/21/2020 at 02:19PM

40
#17 - Martin Kauppinen / @MartinKauppinen

08/16/2020 at 03:32PM

40
#18 - Martin Bielik / @mabielik

08/30/2020 at 03:20PM

42
#19 - analogpixel / @analogp1xel

07/19/2020 at 08:34PM

44
#20 - Jason / @jason_eveleth

07/23/2020 at 06:58AM

44
#21 - Borna Sadeghi / @borna_sadeghi

03/19/2021 at 07:28PM

44
#22 - chriskuck / @chriskuck

03/25/2021 at 03:34PM

48
#23 - Rennnda / @rennnda2020

04/27/2021 at 02:36PM