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 16 remaining solutions by signing in and submitting your own entry
#17 Jason / @jason_eveleth - Score: 44 - 07/23/20 @ 06:58
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>0<CR>4<CR>4<CR>7<CR>5<CR>3<CR>2<Esc>ZZ

0 comments


Created by: @mcr05

17 active golfers, 48 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

31
#3 - Saki Gw / @Sakigw

07/20/2020 at 07:29AM

31
#4 - John Braxler / @braxler

07/21/2020 at 07:02PM

31
#5 - Smylers / @Smylers2

07/27/2020 at 05:59AM

32
#6 - PK / @pkeugine

07/20/2020 at 03:38AM

33
#7 - garry quested / @GQuested

07/20/2020 at 04:39PM

33
#8 - せいほう / @FICSQF

07/23/2020 at 12:31PM

35
#9 - Matt / @mcr05

07/19/2020 at 11:34AM

36
#10 - Norbert / @mullno

07/18/2020 at 08:04PM

36
#11 - Daniel Steinberg / @dstein64

07/18/2020 at 10:35PM

39
#12 - Juan Manuel Fresia / @fresiajm

08/18/2020 at 12:27AM

40
#13 - Seve / @Seve_py

07/21/2020 at 02:19PM

40
#14 - Martin Kauppinen / @MartinKauppinen

08/16/2020 at 03:32PM

40
#15 - Martin Bielik / @mabielik

08/30/2020 at 03:20PM

42
#16 - analogpixel / @analogp1xel

07/19/2020 at 08:34PM

44
#17 - Jason / @jason_eveleth

07/23/2020 at 06:58AM