Awesome
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
- normal mode
- ...
- IME is also multi-mode mostly:
- ASCII mode
- CJKV mode
- ...
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. 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.
dbus
dbus is an inter process communication system. we can communicate with an external IME.
- fcitx5.nvim: for fcitx5
- fcitx5-ui.nvim: for fcitx5
IME outside Vim
- support more hotkeys
- same settings as IME for other windows
- call IME to switch back to ASCII mode when
InsertLeave
by 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
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 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
<!-- markdownlint-disable MD033 -->Editor can provide a popup menu to let user select candidate. If user use <kbd>Ctrl</kbd> + <kbd>P</kbd>/<kbd>N</kbd> to select, input CJKV characters. Otherwise, input ASCII characters.
- more key pressing, the 10-th candidation need 10 times <kbd>Ctrl</kbd> + <kbd>N</kbd>
- ASCII characters cannot be near CJKV characters.
hi nihao
will completenihao
,hinihao
will 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
- ds-pinyin-lsp: only support full pinyin.
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
- vimIM: stop maintenance
- 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
Tips
- For Nix user, run
/the/path/of/luarocks/rocks-5.1/ime.nvim/VERSION/scripts/update.sh
when 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.bash_profile
to run once to speed up:
if [[ -f /run/current-system/nixos-version ]]; then
if [[ -f /the/path/lua/5.1/ime/get-GI_TYPELIB_PATH.nix ]]; then
export GI_TYPELIB_PATH
eval GI_TYPELIB_PATH="$(nix eval --impure -f ~/.local/share/lua/5.1/ime/get-GI_TYPELIB_PATH.nix)"
fi
fi