Rime for neovim.
This project is consist of two parts:
- A lua binding of librime
- A librime frontend on neovim
# Ubuntu
sudo apt-get -y install librime-dev librime1
sudo apt-mark auto librime-dev
# ArchLinux
sudo pacman -S librime
# Android Termux
apt-get -y install librime
# Nix
# use nix-shell to create a virtual environment then build
# homebrew
brew install librime pkg-config
# Windows msys2
pacboy -S --noconfirm pkg-config librime gcc
:Rocks install rime.nvim
~/.config/nvim/rocks.toml
:
[plugins]
"rime.nvim" = "scm"
Then
:Rocks sync
or:
$ luarocks --lua-version 5.1 --local --tree ~/.local/share/nvim/rocks install rime.nvim
# ~/.local/share/nvim/rocks is the default rocks tree path
# you can change it according to your vim.g.rocks_nvim.rocks_path
local Key = require "rime.key".Key
local Session = require "rime.session".Session
local UI = require "rime.ui".UI
local session = Session()
local key = Key {name = "n"}
local ui = UI()
if not session:process_key(key.code, key.mask) then
return
end
local context = session:get_context()
if context == nil then
return
end
content, _ = ui:draw(context)
print(table.concat(content, "\n"))
n|
[① 你]② 那 ③ 呢 ④ 能 ⑤ 年 ⑥ 您 ⑦ 内 ⑧ 拿 ⑨ 哪 ⓪ 弄 |>
A simplest example can be found by:
rime
Set keymap:
local Rime = require('rime.nvim.rime').Rime
local rime = Rime()
rime:create_autocmds()
vim.keymap.set('i', '<C-^>', rime:toggle_cb())
vim.keymap.set('i', '<C-@>', rime:enable_cb())
vim.keymap.set('i', '<C-_>', rime:disable_cb())
Once it is enabled, any printable key will be passed to rime in any case while any non-printable key will be passed to rime only if rime window is opened. If you want to pass a key to rime in any case, try:
vim.keymap.set('i', '<C-\\>', rime:callback('<C-\\>'))
It is useful for some key such as the key for switching input schema.
Lazy load is possible:
local rime = require('rime.nvim')
local ui = require('rime.ui')
rime.rime = { ui = ui.UI { indices = ui.styles.square } }
vim.keymap.set('i', '<C-^>', rime.toggle)
vim.keymap.set('i', '<C-@>', rime.enable)
vim.keymap.set('i', '<C-_>', rime.disable)
vim.keymap.set('i', '<C-\\>', rime.callback('<C-\\>'))
Only when you press <C-^>
, Rime():create_autocmds()
will be call, which will
save time.
Once you switch to ascii mode of rime, you cannot switch back unless you have defined any hotkey to pass the key for switching ascii mode of rime to rime. Because only printable key can be passed to rime when rime window is closed.
set guicursor=n-v-c-sm:block-Cursor/lCursor,i-ci-ve:ver25-CursorIM/lCursorIM,r-cr-o:hor20-CursorIM/lCursorIM
local Cursor = require('rime.nvim.hooks.cursor').Cursor
local cursor = Cursor {
schemas = {
[".default"] = { bg = 'white' },
double_pinyin_mspy = { bg = 'red' },
japanese = { bg = 'yellow' }
}
}
local rime = Rime {
hook = cursor
}
In insert/replace/select/... mode, it will display current input schema name.
You can customize it. Such as:
Only display input schema name in insert mode:
local Airline = require('rime.nvim.hooks.airline').Airline
local airline = Airline()
function airline.get_new_mode(mode, old, name)
if mode == 'i' then
return name
end
return old
end
local rime = Rime {
hook = airline
}
See airline's g:airline_mode_map
to know i
, R
, s
, ...
Disable all hooks:
local ChainedHook = require('rime.nvim.hooks.chainedhook').ChainedHook
local hook = ChainedHook { }
-- by default
-- local hook = ChainedHook { cursor, airline }
local rime = Rime {
hook = hook
}
Like cmp-rime:
require('cmp').setup {
-- ...
sources = {
-- ...
{ name = 'rime' }
}
}
ime.nvim
uses:set iminsert=1/0
and:set imsearch=1/0
to save external IME's enabled flags.rime.nvim
uses:let/unlet b:iminsert
to save internal IME's enabled flags.
So they will not conflict.
PS: both of them share same abstract class IME
between require'rime.ime'
and
require'ime.ime'
.
For Nix user, run
/the/path/of/luarocks/rocks-5.1/rime.nvim/VERSION/scripts/update.sh
when
dynamic link libraries are broken after nix-collect-garbage -d
.
- pyrime: a python binding of librime. Practically, a vim plugin with the same feature as this plugin by python implementation is possible. Like cmp-rime.
- coc-rime: nodejs implementation. Inactive maintenance.
- A collection of the solutions to input CJKV characters in vim
- A collection of rime frontends
- librime-lua: use lua to write translators and filters of librime
- librime-python: use python
- librime-qjs: use quickjs