为 Vim/Neovim 提供基于 jieba 的 word motion / text object 增强。
For English, see below.
- 混合架构:Vimscript 负责集成,Rust 核心通过 cdylib 提供高性能分词;预编译二进制托管于 GitHub Releases,覆盖主流平台。两者通过 python3 (Vim) 或 lua5.1 (Neovim) 桥接。
- 兼容性保障:48,000+ 自动化 Vim 用例验证,确保在纯 ASCII 文本中与原生 word motions / text objects 行为完全一致。
- 完整支持:全部 12 个 word motions / text objects(
w/W/b/B/e/E/ge/gE/iw/iW/aw/aW),覆盖 normal / visual / operator-pending 模式,支持计数前缀与所有字符操作,支持 register,以及通过tpope/vim-repeat支持.重复上一操作。 - 灵活配置:尊重
'iskeyword'设置,允许自定义分词边界;支持惰性加载词典,按需启用。 - 帮助文档:可使用
:h jieba在 Vim/Nvim 内查看帮助。
- Vim 8/9:需要
+python3或+python3/dyn或+python3/dyn-stable。 - Neovim:无额外依赖。
vim-plug (Vim / Neovim):
Plug 'kkew3/jieba.vim', { 'tag': 'v2.1.0', 'do': { -> jieba_vim#install() } }lazy.nvim (Neovim):
{
"kkew3/jieba.vim",
tag = "v2.1.0",
build = ":call jieba_vim#install()",
init = function()
vim.g.jieba_vim_lazy = 1
vim.g.jieba_vim_keymap = 1
end,
},其中,jieba_vim#install() 优先下载预编译 cdylib,下载失败时回退至本地编译(需要 cargo)。
- 在保留原生语义(如
w不跳过标点、W跳过标点)的基础上,使以下命令识别中文词语:- Word motions:
b、B、ge、gE、w、W、e、E - Text objects:
iw、iW、aw、aW
- Word motions:
- 支持所有模式:
nmap/xmap/omap(text object 没有nmap); - 支持计数:
4w、c2e、3daw等; - 支持所有字符操作:
d、c、y、g~等; - 安装有
tpope/vim-repeat时可以使用.重复上一操作:dw.相当于dwdw。
可提前高亮 nmap 下的光标跳转位置:
" 示例映射
nmap <LocalLeader>jw <Plug>(Jieba_preview_w)
nmap <LocalLeader>je <Plug>(Jieba_preview_e)
" 取消预览
nmap <LocalLeader>jc <Plug>(Jieba_preview_cancel)另提供 :JiebaPreviewCancel 命令用于取消按词跳转位置预览。
当前暂不支持预览 text objects。
默认不映射任何按键,通过 <Plug>(Jieba_*) 映射与命令供用户自由配置。若希望快速启用默认行为(不包括跳转预览),可在 ~/.vimrc 中:
let g:jieba_vim_keymap = 1| 选项 | 说明 | 默认值 |
|---|---|---|
g:jieba_vim_lazy |
是否延迟加载词典直到中文出现 | 1(是) |
g:jieba_vim_user_dict |
用户自定义词典路径 | "" |
g:jieba_vim_keymap |
是否自动启用默认键映射 | 0(否) |
若想在本地运行针对 rust 实现的测试,部分测试可通过如下命令运行:
cargo test --locked -r --manifest-path rust_backend/Cargo.toml其余测试比较复杂,请参见 CI。
见 TODO.md。
见 RELATED.md。
Apache license v2;部分文件参照 vim-LICENSE.txt.
- Hybrid Architecture: Vimscript handles integration while the Rust core delivers high-performance word segmentation via cdylib; precompiled binaries are hosted on GitHub Releases, covering major platforms. Rust and Vimscript are bridged by python3 (Vim) or lua5.1 (Neovim).
- Compatibility Assurance: 48,000+ automated Vim test cases ensure behavior fully consistent with native word motions / text objects when handling pure ASCII text.
- Complete Support: All 12 word motions / text objects (
w/W/b/B/e/E/ge/gE/iw/iW/aw/aW), covering normal / visual / operator-pending modes, supporting count prefixes and all character operators, supporting registers, and supporting.to repeat the last operation via tpope/vim-repeat. - Flexible Configuration: Respects
'iskeyword'settings, allowing custom word boundary definitions; supports lazy-loading dictionaries, enabling on-demand activation. - Help documentation: Check the help documentation with
:h jiebawithin Vim/Nvim.
- Vim 8/9: require
+python3or+python3/dynor+python3/dyn-stable. - Neovim: no additional dependency.
vim-plug (Vim / Neovim):
Plug 'kkew3/jieba.vim', { 'tag': 'v2.1.0', 'do': { -> jieba_vim#install() } }lazy.nvim (Neovim):
{
"kkew3/jieba.vim",
tag = "v2.1.0",
build = ":call jieba_vim#install()",
init = function()
vim.g.jieba_vim_lazy = 1
vim.g.jieba_vim_keymap = 1
end,
},Here, jieba_vim#install() prioritizes downloading the precompiled cdylib, falling back to local compilation (requires cargo) if the download fails.
- While preserving native semantics (e.g.,
wdoes not skip punctuation, whereasWdoes), the following commands are enhanced to recognize Chinese words:- Word motions:
b、B、ge、gE、w、W、e、E - Text objects:
iw、iW、aw、aW
- Word motions:
- Supports all modes:
nmap/xmap/omap(text objects have nonmap); - Supports counts:
4w,c2e,3daw, etc.; - Supports all character operators:
d,c,y,g~, etc.; - When tpope/vim-repeat is installed,
.can be used to repeat the last operation:dw.is equivalent todwdw.
Cursor movements under nmap can be previewed in advance:
" Example mappings
nmap <LocalLeader>jw <Plug>(Jieba_preview_w)
nmap <LocalLeader>je <Plug>(Jieba_preview_e)
" Cancel preview
nmap <LocalLeader>jc <Plug>(Jieba_preview_cancel)Additionally, the :JiebaPreviewCancel command is provided to cancel word motion previews.
Preview for text objects is currently not supported.
By default, no keys are mapped; users can freely configure via <Plug>(Jieba_*) mappings and commands. If you wish to quickly enable default behavior (excluding cursor movement preview), add the following to ~/.vimrc:
let g:jieba_vim_keymap = 1| Option | Description | Default |
|---|---|---|
g:jieba_vim_lazy |
Whether to delay loading the dictionary until Chinese characters appear | 1 (yes) |
g:jieba_vim_user_dict |
Path to user-defined custom dictionary | "" |
g:jieba_vim_keymap |
Whether to automatically enable default key mappings | 0 (no) |
To run tests against the Rust implementation locally, a portion of tests can be executed with the following command:
cargo test --locked -r --manifest-path rust_backend/Cargo.tomlFor the remaining, please refer to CI.
See TODO.md.
See RELATED.md.
Apache License v2; with a handful of files following vim-LICENSE.txt.