ime.nvim
Switch back from IME after InsertLeave. Powered by dbus.
Introduction
Multi-mode IME
- Vim (include other editors who have a vim emulator) is mulit-mode editor:
- insert mode: press
jkhlto inputjkhl - normal mode: press
jkhlto move cursor - ...
- IME is also multi-mode mostly:
- ASCII mode: press
nihaoto inputnihao - CJKV mode: press
nihaoto input你好 - ...
In insert mode, we can switch IME mode to input ASCII characters or CJKV characters. However, in other modes of Vim, only ASCII mode can work: Vim will not response any CJKV character.
| Vim/IME | ASCII | CJKV | | ------- | ------- | ------- | | insert | :smile: | :smile: | | normal | :smile: | :cry: |
So we must switch back from IME after InsertLeave.
Currently, we have two schemes to realize it:
IME inside Vim
no dependencies of GUI
support remote machines: ssh, telnet, ...
Vim passes user's input to IME by librime/dbus
IME passes the result to Vim by librime/dbus
Vim draw UI of Vim IME window
When user
InsertLeave, we close Vim IME window.
librime
librime is a library for creating IME.
- rime.nvim: written in lua
- coc-rime: written in javascript. Inactive maintenance.
- pyrime.nvim: written in python. Inactive maintenance.
dbus
dbus is an inter process communication system. we can communicate with an external IME.
- fcitx5.nvim: for fcitx5. You must disable fcitx5 in GUI to make it work.
- fcitx5-ui.nvim: for fcitx5. this project rewrite fcitx5.nvim to support using fcitx5 in both GUI and neovim.
check if corresponding Input method frontend is disabled in Fcitx5 configuration, if your terminal/GUI support that. Otherwise, your terminal/GUI will capture your keystrokes and sent them to Fcitx5 instead of Neovim.
-- fcitx5.nvim
IME outside Vim
support more hotkeys
same settings as IME for other windows
call IME to switch back to ASCII mode when
InsertLeaveby CLI/dbus
CLI
Some IMEs provide a CLI program to switch mode.
- issw: for macOS
- macism: for macOS
- im-select: for macOS and Windows
ibus engine: for ibusfcitx-remote: for fcitx5g3kb-switch: for ibus, and provide a DLLxkb-switch: for xim, and provide a DLLxkb-switch(for macOS): for macOS, and provide a DLL
Some Vim plugins use CLI:
- nvim-auto-ime: only support macism
- coc-imselect: only support im-select
- im-select.nvim: support im-select, ibus engine, fcitx-remote
- alohaia/fcitx.nvim: only support fcitx-remote
- h-hg/fcitx.nvim: only support fcitx-remote
- vim-barbaric: support ibus engine, fcitx-remote, xkb-switch
- nvim-ibus-sw: only support ibus engine
dbus
- vim-xkbswitch: support g3kb-switch, xkb-switch and issw by their DLLs, where g3kb-switch utilizes dbus and is written in C
- fcitx.vim: support fcitx and fcitx5-rime. written in python
- This plugin: support
- fcitx5: with or without rime input schema
- ibus
- gnome-shell: you can get IME information from gnome-shell whatever you use
which IME. You need [unsafe-mode-menu](https://github.com/linushdot/unsafe-mode-menu) to open unsafe mode in latest gnome-shell. - g3kb-switch: or use it to bypass security prohibit.
In Gnome 41 and newer, the switcher will only work with G3kbSwitch Gnome Shell extension, because method org.gnome.Shell.Eval which was used in the original implementation of the switcher is now disabled for security reasons
-- g3kb-switch
single-mode IME

Editor can provide a popup menu to let user select candidate. If user use Ctrl + P/N to select, input CJKV characters. Otherwise, input ASCII characters.
- more key pressing, the 10-th candidation need 10 times Ctrl + N
- ASCII characters cannot be near CJKV characters. Many languages support
variable names containing Unicode, so completions after CJKV characters will
be ignored.
hi nihaowill completenihao,hinihaowill completehinihao. However, it shouldn't happen. Because:
中英文之間需要增加空格
-- 中文文案排版指北
We can create:
- a language server to support all editors which supports LSP. The editor will manage the popup menu according to LSP.
- an editor specific plugin.
- register a completion source of other editor plugins which manage the popup
menu
- manage the popup menu by itself
LSP
由于 rime-ls 并不是 LSP 的常规用法,难以要求编辑器来适配 rime-ls
-- rime-ls
- ds-pinyin-lsp: only support full pinyin.
- rime-ls: inspired from ds-pinyin-lsp.
coc.nvim
- coc-rime: written in javascript
nvim-cmp
Manage popup menu by itself
Manage popup menu by itself will result in the conflict with other editor plugins which manage the popup menu. At the same time, you must enable one of them.
Sorry, you have to make the choice.
-- coc-snippets
- boshiamy-cue.vim: the oldest solution
- vimIM: stop maintenance
- vim-boshiamy: forked from vimIM
- ime.vim: a light weight alternative of vimIM
- ZFVimIM: a rewrite of vimIM. It will disable most completion plugins when it is enabled.
Dependencies
# Ubuntu sudo apt-get -y install libgirepository-1.0-1 libgirepository1.0-dev pkg-config sudo apt-mark auto libgirepository1.0-dev pkg-config # ArchLinux sudo pacman -S libgirepository pkg-config # Android Termux apt-get -y install gobject-introspection pkg-config # Nix # use nix-shell to create a virtual environment then build
Install
rocks.nvim
Command style
:Rocks install ime.nvim
Declare style
~/.config/nvim/rocks.toml:
[plugins] "ime.nvim" = "scm"
Then
:Rocks sync
or:
$ luarocks --lua-version 5.1 --local --tree ~/.local/share/nvim/rocks install ime.nvim # ~/.local/share/nvim/rocks is the default rocks tree path # you can change it according to your vim.g.rocks_nvim.rocks_path
lazy.nvim
require("lazy").setup { spec = { { "rimeinn/ime.nvim", lazy = false }, }, }
Tips
- For Nix user, run
/the/path/of/luarocks/rocks-5.1/ime.nvim/VERSION/scripts/update.shwhen dynamic link libraries are broken afternix-collect-garbage -d. - For NixOS,
require'dbus_proxy'needs correctvim.env.GI_TYPELIB_PATH. This plugin will do it out of box. You also can add the following code to run once to speed up:
/etc/nixos/configuration.nix:
environment.variables = {
GI_TYPELIB_PATH =
let
suffix = "lib/girepository-1.0";
in
"${pkgs.glib.out}/${suffix}:${pkgs.gobject-introspection}/${suffix}:${pkgs.gobject-introspection.unwrapped}/${suffix}";
};