Created
November 9, 2010 15:13
-
-
Save h1mesuke/669204 to your computer and use it in GitHub Desktop.
Vim - A port of Ruby's abbrev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"----------------------------------------------------------------------------- | |
" 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