DEV Community

Andy Stewart
Andy Stewart

Posted on

20 Years of Linux Input Method Tweaking: From Kernel Drivers to AI Models—The Ultimate Form of Input Experience

Having spent 20 years navigating the open-source world and the Linux community—from building Deepin OS to developing EAF—I’ve always held one conviction: A programmer’s sense of achievement comes half from changing the world, and half from the ultimate refinement of their tools. Many ask me why I still spend so much energy on RIME configurations in the age of AI. It's because an input method is an extension of one's thoughts. Every missed character or mistyped toggle between Chinese and English is a profanity against the "Flow State."

I’ve tested Rime-Ice, Rime-Frost, and Wanxiang, but ultimately returned to Rime-Ice. Wanxiang’s pinyin mode was simply too frustrating due to frequent accidental triggers. Today, I’m organizing all my Fcitx configuration practices into this post. This isn't just a tutorial; it’s a tribute to the open-source community’s spirit of "standing on the shoulders of giants." Since I’ve benefited from the wheels others built, I must contribute my polished solutions back.

If you are an Arch Linux user, congratulations—you don't need to mess with the command lines below. You can simply use my tool, rime-ice-installer, which automatically installs and applies all the configurations mentioned here.

yay -S rime-ice-installer
rime-ice-installer

Features of rime-ice-installer:

1.Installs Fcitx and Rime-Ice (Wusong).
2.Automatically configures X11/Wayland environments.
3.Automatically configures the Wanxiang AI Large Model.
4.Configures convenient habits, such as using commas and periods for paging by default.
5.Includes a dark-theme-friendly skin.
6.Most importantly: It maps the Shift key to switch the system's English layout rather than entering Fcitx's internal "English Mode." Once Fcitx's English mode is triggered accidentally, it's notoriously difficult to switch back via the keyboard, often requiring a mouse click on the system tray.

Installing Fcitx5
Install the Fcitx5 packages:

sudo pacman -S fcitx5 fcitx5-gtk fcitx5-qt fcitx5-configtool fcitx5-rime librime

  • fcitx5: Core input method framework.
  • fcitx5-gtk: Support for GTK applications. Essential for fixing missing characters during fast typing.
  • fcitx5-qt: Support for QT5 applications. Essential for fixing missing characters during fast typing.
  • fcitx5-configtool: GUI configuration tool.
  • fcitx5-rime: RIME input method engine.
  • fcitx5-im: Input method setup tool.
  • librime: RIME libraries, required by emacs-rime below.

Wayland Environment Setup
After installing the packages, in a KDE environment, simply go to KDE Settings -> Virtual Keyboard, select Fcitx5, and log out/in.

For specific apps like WeChat that fail to support Chinese input, you need to create the configuration file ~/.config/plasma-workspace/env/ime.sh and add:

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"

After logging out and back in, you should be able to type Chinese in WeChat under Wayland.

Notes:
You must install fcitx5-gtk and fcitx5-qt and set the IM variables above, otherwise, typing too fast will result in "character leaking," where the pinyin is inserted directly into the input box instead of converting to Hanzi.

Add-ons: Remove the shortcuts for the clipboard and quick input modules to avoid conflicts with Emacs keybindings.

X11 Environment Setup
For X11, write the following to ~/.xprofile:

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"

Log in again to apply.

Notes:
Same as Wayland, ensure fcitx5-gtk and fcitx5-qt are installed to prevent character leaking.

Disable clipboard/quick input shortcuts to avoid Emacs conflicts.

Installing Fcitx5 Skins
yay -S fcitx5-skin-adwaita-dark

Then modify the config file ~/.config/fcitx5/conf/classicui.conf:
`Horizontal candidate list
Vertical Candidate List=False

Prevent font scaling with DPI to avoid oversized interface
PerScreenDPI=False

Font and size (check options with fc-list)
Font="Noto Sans Mono 13"

Gnome3-style theme
Theme=adwaita-dark`

Note: I personally prefer "TsangerJinKai03," so you can replace the Font with TsangerJinKai03-6763 15.

Installing Rime-Ice (Wusong Pinyin)
The steps above set up the core and skin, but the default Fcitx dictionary is quite poor. For a fluid experience, you need Rime-Ice.
Copy all rime-ice configurations to the fcitx rime directory:

git clone https://github.com/iDvel/rime-ice --depth=1

Modifying Default Configurations
Switch to the rime-ice directory and perform these three operations:
1.grep all- { when: paging, accept: comma, send: Page_Up } 和 - { when: has_menu, accept: period, send: Page_Down } ,Remove the annotations
2.grep page_size, change 5 to 9.

`sed -i 's/# (- { when: (paging|has_menu), accept: (comma|period), send: Page_(Up|Down) })/\1/' default.yaml

sed -i 's/page_size: 5/page_size: 9/' default.yaml`

he first two enable paging with commas and periods; the third increases the number of candidate words.

Adding Large Language Models
While Rime-Ice is already quite smart, we can enhance context-based suggestions by installing a Wanxiang language model.

The specific operation method is as follows:
Download rime-lmdg. I downloaded the amz-v2n3m1-zh-hans.gram file.

Move the file amz-v2n3m1-zh-hans.gram to the rime-ice directory.

Create a new rime-ice.custom.yaml file in the rime-ice directory with the following contents:

patch:
grammar:
language: amz-v2n3m1-zh-hans
collocation_max_length: 5
collocation_min_length: 2
translator/contextual_suggestions: true
translator/max_homophones: 7
translator/max_homographs: 7

Updating the Fcitx Directory
After adjusting the configs, perform the copy. Backup and clear ~/.config/fcitx/rime/ and ~/.local/share/fcitx5/rime first to avoid conflicts.

cp -r ./rime-ice/* ~/.config/fcitx/rime/
cp -r ./rime-ice/* ~/.local/share/fcitx5/rime

~/.config/fcitx/rime/: Primarily read by the emacs-rime plugin.

~/.local/share/fcitx5/rime: Read by Fcitx for external software.

Deleting Accidental Input
If you accidentally confirm a pinyin string, it might become the first candidate. These are recorded here:

~/.local/share/fcitx5/rime/en_dicts/en.dict.yaml ~/.config/fcitx/rime/en_dicts/en.dict.yaml
Find the errant string, delete it, save, and restart Fcitx.

Installing emacs-rime
This section is about bringing Rime-Ice into Emacs.
First, install posframe, and then download emacs-rime:

git clone https://github.com/DogLooksGood/emacs-rime

Add the directory to your load-path and add the following config:

`(require 'rime)

;;; Code:
(setq rime-user-data-dir "~/.config/fcitx/rime")

(setq rime-posframe-properties
(list :background-color "#333333"
:foreground-color "#dcdccc"
:font "WenQuanYi Micro Hei Mono-14"
:internal-border-width 10))

(setq default-input-method "rime"
rime-show-candidate 'posframe)`

The configurations above respectively set the path for emacs-rime to read RIME configurations, the UI details, and the use of posframe to display candidate words.

After restarting Emacs, invoke the toggle-input-method command to try typing in Chinese.

The Rime-Ice home page provides several input examples. If typing the same pinyin yields the identical Chinese candidate words, it confirms that you have successfully implemented Rime-Ice.

In my personal experience, the fine-tuning of Rime-Ice is exceptional—far more professional than any RIME dictionary I’ve tried to cobble together myself. Chinese input, especially for long sentences, no longer requires flipping through endless pages of candidates.

The combination of emacs-rime and Rime-Ice makes Chinese input in Emacs an absolute joy. I’ve personally sent a small donation to the author of Rime-Ice to show my appreciation for their hard work and contribution to the open-source community!

Top comments (0)