Skip to content

Instantly share code, notes, and snippets.

@h1mesuke
Created November 9, 2010 15:13
Show Gist options
  • Save h1mesuke/669204 to your computer and use it in GitHub Desktop.
Save h1mesuke/669204 to your computer and use it in GitHub Desktop.
Vim - A port of Ruby's abbrev
"-----------------------------------------------------------------------------
" Abbrev
function! util#abbrev(words)
let table = {}
let seen = {}
for word in a:words
let abbrev = substitute(word, '.$', '', '')
let ablen = strlen(abbrev)
while ablen > 0
if !has_key(seen, abbrev)
let seen[abbrev] = 0
endif
let seen[abbrev] += 1
if seen[abbrev] == 1
let table[abbrev] = word
elseif seen[abbrev] == 2
unlet table[abbrev]
else
break
endif
let abbrev = substitute(abbrev, '.$', '', '')
let ablen = strlen(abbrev)
endwhile
endfor
for word in a:words
let table[word] = word
endfor
return table
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment