Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Chinese characters for PinYin initials #455

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions autoload/EasyMotion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function! EasyMotion#init()
let s:dot_repeat = {}
" Prepare 1-key Migemo Dictionary
let s:migemo_dicts = {}
" Prepare Chinese Dictionary
let s:chinese_dict = {}
let s:EasyMotion_is_active = 0
call EasyMotion#reset()
" Anywhere regular expression: {{{
Expand Down Expand Up @@ -571,6 +573,8 @@ function! s:convertRegep(input) "{{{

if use_migemo
let re = s:convertMigemo(re)
elseif g:EasyMotion_use_Chinese
let re = s:convertChinese(re)
endif

if s:should_use_smartsign(a:input)
Expand All @@ -587,6 +591,29 @@ function! s:convertRegep(input) "{{{
let re = case_flag . re
return re
endfunction "}}}
function! s:convertChinese(re) "{{{
if empty(s:chinese_dict)
let s:chinese_dict = EasyMotion#Chinese#load_dict()
" patch the Chinese dictionary to include the upper case English
" letter as hits
if g:EasyMotion_Chinese_SearchUpper
for idx in range(97, 122)
let key = nr2char(idx)
if has_key(s:chinese_dict, key)
let needle = s:chinese_dict[key]
let s:chinese_dict[nr2char(idx)] = needle[0:1] . nr2char(idx-32).needle[2:]
else
let s:chinese_dict[nr2char(idx)] = '['.nr2char(idx).nr2char(idx-32).']'
endif
endfor
endif
endif
let regString = ''
for ch in split(a:re, '\zs')
let regString .= get(s:chinese_dict, ch, ch)
endfor
return regString
endfunction "}}}
function! s:convertMigemo(re) "{{{
let re = a:re

Expand Down
Loading