easymotion / vim-easymotion

Vim motions on speed!
http://www.vim.org/scripts/script.php?script_id=3526
7.44k stars 357 forks source link

Add support to Chinese characters for PinYin initials #455

Open TroyDanielFZ opened 3 years ago

TroyDanielFZ commented 3 years ago

I added the support for Chinese PinYin initials, and hope to help others.

VimWei commented 3 years ago
  1. 这个不能同时兼容中英文混合检索,建议将英文字母表映射为其自身的小写和大写,如,将a映射为A、a It isn't compatible with both Chinese and English search. It is recommended that the English alphabet be mapped to its own lowercase and uppercase. For example, map a to a and A.

  2. 好像只支持单字符的检索,不支持 (easymotion-sn) 等多字符的情形 It seems to support only single-character retrieval, not multi-character situation, such as (easymotion-sn) .

  3. 建议参考这个进行改进 Consider this for an update https://github.com/ppwwyyxx/vim-pinyinsearch

TroyDanielFZ commented 3 years ago
  1. 这个不能同时兼容中英文混合检索,建议将英文字母表映射为其自身的小写和大写,如,将a映射为A、a It isn't compatible with both Chinese and English search. It is recommended that the English alphabet be mapped to its own lowercase and uppercase. For example, map a to a and A.
  2. 好像只支持单字符的检索,不支持 (easymotion-sn) 等多字符的情形 It seems to support only single-character retrieval, not multi-character situation, such as (easymotion-sn) .
  3. 建议参考这个进行改进 Consider this for an update https://github.com/ppwwyyxx/vim-pinyinsearch
    • 我理解的中英文混合检索是,当我从<Plug>(easymotion-f)开始,接下来将会把英文单词里的a,以及中文汉字里以a开头的汉字作为备选位置并高亮。那么,在我这儿是能进行中英文混合检索的。如果你所指的中英文混合检索不是该意思,请详细描述其含义;如果是该意思,则希望你能提供一些更详细的信息。此外,关于添加A,我个人毕竟喜欢区分大小写。不过可以考虑在后续把此方案做成选项。
    • 因为此前我没有使用多字符检索,所以在此前的提交里未作相应的修改。我将在有空的时候继续修改。
    • vim-PinyinSearch也是为了支持上述的多字符跳转?
draftman9 commented 2 years ago

I added the support for Chinese PinYin initials, and hope to help others.

不知道是否可以支持五笔、郑码,甚至自定义码表(7000常用汉字即可)?

TroyDanielFZ commented 2 years ago

不知道是否可以支持五笔、郑码,甚至自定义码表(7000常用汉字即可)?

修改vim-easymotion\autoload\EasyMotion\Chinese.vim里a-z所对应的正则即可。

draftman9 commented 2 years ago

不知道是否可以支持五笔、郑码,甚至自定义码表(7000常用汉字即可)?

修改vim-easymotion\autoload\EasyMotion\Chinese.vim里a-z所对应的正则即可。

我下载了你的easymotion,出现了Chinese.vim文件,我发现“w”对应的有“我”,但却无正常使用。比如说在txt文件中搜索“我”,我按 <Leader>fw ,显示 No matches,而我看到了一个“我”字。 请问这是怎么回事? 我需要设置其他参数吗?我的配置是:

map s <Plug>(easymotion-bd-f2)
nmap S <Plug>(easymotion-overwin-f2)
map <Leader>h <Plug>(easymotion-linebackward)
map <Leader>l <Plug>(easymotion-lineforward)
map <Leader>f <Plug>(easymotion-bd-f)
TroyDanielFZ commented 2 years ago

@draftman9 你只需要在你的VIMRC里添加let g:EasyMotion_use_Chinese = 1即可。我在提交的时候,没有把中文拼音首字母设为默认。 The Chinese PinYin intials are disabled by default.

draftman9 commented 2 years ago

@draftman9 你只需要在你的VIMRC里添加let g:EasyMotion_use_Chinese = 1即可。我在提交的时候,没有把中文拼音首字母设为默认。 The Chinese PinYin intials are disabled by default.

  • 我理解的中英文混合检索是,当我从<Plug>(easymotion-f)开始,接下来将会把英文单词里的a,以及中文汉字里以a开头的汉字作为备选位置并高亮。那么,在我这儿是能进行中英文混合检索的。

现在我可以检索中文了,但同时,我却无法检索英文字母了,更别提中英混检了。我配置中的 <Leader>f 映射的是<Plug>(easymotion-bd-f),而我看到你在文档中举的例子都是<Plug>(easymotion-f),我无法搜索英文字母或无法中英混检是与此有关吗?

TroyDanielFZ commented 2 years ago

没有关系啊。要不你手动在Chinese.vim里EasyMotion#Chinese#load_dict中的字典里加上英文字母吧,如,...'a' : '[仰伌佁...变成...'a' : '[a仰伌佁...

draftman9 commented 2 years ago

没有关系啊。要不你手动在Chinese.vim里EasyMotion#Chinese#load_dict中的字典里加上英文字母吧,如,...'a' : '[仰伌佁...变成...'a' : '[a仰伌佁...

这的确是一个办法。 但是从该Issue中您的Comments推断,您中英混检时,应该不是这样做的吧😄?不然您一定会在chinese.vim直接填加上字母的。另外,我更偏好更改设置而非直接修改插件文件内容。所以如果有其他更简单的办法,请您告知我。

TroyDanielFZ commented 2 years ago

@draftman9 我是在autoload/easymotion.vim中的function! s:convertChinese(re)中使用了

let s:chinese_dict[nr2char(idx)] = '['.nr2char(idx).nr2char(idx-32).']'

把英文字母添加到这个字典里的,你可以从这里看修改。你看看你下载下来的里面有相应的修改吗?

lbgws2 commented 1 year ago

I spent some time solving this problem

  1. Download this utf8.vim file here and replace it with the utf8.vim file in ../plugged/vim-easymotion/autoload/EasyMotion/migemo

The file encoding should be utf-8 not need https://github.com/ZSaberLv0/vim-easymotion-chs or https://github.com/zzhirong/vim-easymotion-zh

  1. set in vimrc

let g:EasyMotion_use_migemo = 1 
nmap <Leader>f <Plug>(easymotion-s)

The result is like this: image

image

It Use PinYin initials positioning

Support for Chinese polyphonic characters

Can mix Chinese and English recognition, including uppercase and lowercase English

Can recognize Chinese punctuation

More than 6000 commonly used simplified Chinese characters

Question:

Only a single character can be recognized,

If you need to customize your own code table, just modify utf8.vim