Skip to content

Instantly share code, notes, and snippets.

@davidxifeng
Created January 10, 2012 06:21
Show Gist options
  • Save davidxifeng/1587378 to your computer and use it in GitHub Desktop.
Save davidxifeng/1587378 to your computer and use it in GitHub Desktop.
A hashset of my vim scripts
"also my gist test
"get words count of current line
echo "current line words count : ".len(split(getline(".")))
"Double Pinyin Schema
let s:yunmu={ "iu": "q", "ia": "w", "ua": "w", "e": "e", "uan": "r", "er": "r", "ue": "t",
\ "uai": "y", "v": "y", "u": "u", "i": "i", "uo": "o","o":"o", "un": "p",
\ "a":"a","ong":"s","iong":"s","uang":"d","iang":"d","en": "f","eng":"g",
\ "ang": "h", "an": "j", "ao": "k", "ai":"l", "ing":";",
\ "ei": "z", "ie": "x", "iao": "c", "ui": "v", "ou": "b",
\ "in": "n", "ian": "m" }
let s:shengmu={"zh":"v","ch":"i","sh":"u"}
"input assume: exactly correct shengmu.
function! s:process(filename)
let newFile=[]
for line_read in readfile(a:filename)
let words=split(line_read)
let newWords=[]
let first=1
for c in words
if first
let first = 0
"skip the hanzi
call add(newWords,c)
else
if has_key(s:yunmu, c)
" a->oa an-oj ...
call add(newWords,'o'.s:yunmu[c])
else
if c[1] == 'h'
" zha -> va shuang -> ud ...
let shengmu=c[:1]
let yunmu=c[2:]
if has_key(s:shengmu,shengmu) && has_key(s:yunmu,yunmu)
let shuangpin=s:shengmu[shengmu].s:yunmu[yunmu]
call add(newWords,shuangpin)
endif
else
" common fa -> fa dang -> dh
let shengmu=c[0]
let yunmu=c[1:]
if has_key(s:yunmu,yunmu)
let shuangpin=shengmu.s:yunmu[yunmu]
call add(newWords,shuangpin)
endif
endif
endif
endif
endfor
"write to file
call add(newFile,join(newWords," "))
endfor
call writefile(newFile,"/tmp/fnewDict.v")
endfunction
call s:main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment