Skip to content

Freed-Wu/ime.nvim

Repository files navigation

ime.nvim

pre-commit.ci status github/workflow

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

luarocks

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

IME inside Vim

  • no dependencies of GUI
  • support remote machines: ssh, telnet, ...
  1. Vim passes user's input to IME by librime/dbus
  2. IME passes the result to Vim by librime/dbus
  3. Vim draw UI of Vim IME window
  4. When user InsertLeave, we close Vim IME window.

librime is a library for creating IME.

dbus is an inter process communication system. we can communicate with an external IME.

IME outside Vim

IME outside Vim

  • support more hotkeys
  • same settings as IME for other windows
  1. 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 ibus
  • g3kb-switch: for ibus, and provide a DLL
  • xkb-switch: for xim, and provide a DLL
  • fcitx-remote: for fcitx5

Some Vim plugins use CLI:

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

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. hi nihao will complete nihao, hinihao will complete hinihao. 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

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

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

For NixOS, export $GI_TYPELIB_PATH in your shell profile to make require'dbus_proxy' work. Refer my ~/.bash_profile.