How to Enable Automatic Capitalization for English Input in Wanxiang Rime

The Wanxiang Rime schema enables automatic capitalization for English input by processing raw keystrokes through the super_english.lua filter, which detects capital letter patterns in your typing and applies matching case formatting to English candidates.

The amzxyz/rime_wanxiang repository ships with a dedicated English input schema that automatically capitalizes words based on your typing rhythm. Unlike standard Rime schemas that require manual case switching, the Wanxiang implementation analyzes your raw input code in real-time to determine whether to capitalize the first letter or the entire word. This guide walks you through activating this feature using the built-in wanxiang_english schema and super_english Lua filter.

How the Capitalization Filter Works

The automatic capitalization logic resides in the super_english.lua filter, which Rime loads through the wanxiang_english.schema.yaml configuration. When active, the filter intercepts English candidates after the speller and recognizer stages but before they reach the selector.

Core Implementation Details

In wanxiang/lua/super_english.lua, the apply_segment_formatting() function receives two critical parameters: text (the candidate word) and input_code (your raw keystrokes). The function compares each word against its corresponding slice of the input segment using Lua pattern matching:

  • All caps detection: If the input segment starts with two capital letters (^%u%u), the filter applies string.upper to the entire word.
  • First letter capitalization: If the segment starts with a single capital letter (^%u), the filter uses gsub(..., "^%a", upper) to capitalize only the first letter.

This processing happens automatically for every English candidate, ensuring that typing Hello produces "Hello" while typing HE produces "HE" or "HELLO" depending on the dictionary match.

Pipeline Configuration

The filter is declared in wanxiang/wanxiang_english.schema.yaml within the filters section:

filters:
  - lua_filter@*auto_phrase
  - lua_filter@*super_english   # English auto-formatting (capitalization + spacing)

  - uniquifier

The filter runs only when the english_spacing option is set to any value except off (valid options include smart, before, or after). This option acts as the master switch for the super_english filter's formatting logic.

Enabling Automatic Capitalization

To activate automatic capitalization for English input, you must load the English schema and ensure the filter is not disabled.

1. Add the English Schema to Your Schema List

Edit your default.yaml (or custom.yaml patch) to include wanxiang_english in the schema list:


# ~/.config/ibus/rime/default.yaml

schema_list:
  - schema: wanxiang          # Core Chinese schema

  - schema: wanxiang_english  # English schema with auto-capitalization

2. Verify the Spacing Option

Ensure the english_spacing option in wanxiang_english.schema.yaml is not set to off:


# wanxiang_english.schema.yaml

wanxiang_english:
  english_spacing: smart   # Enables capitalization logic

Setting this to smart, before, or after keeps the capitalization logic active. Setting it to off disables the entire super_english filter.

3. Deploy and Reload

Deploy your Rime configuration (typically Ctrl+Shift+R or via your input method's menu). Once reloaded, typing English words with initial capitals or all capitals in your raw input will automatically format the candidates to match.

Practical Configuration Examples

Minimal User Patch

Create or edit custom.yaml to enable the feature without modifying core schema files:


# ~/.local/share/ibus/rime/custom.yaml

patch:
  schema_list:
    - schema: wanxiang
    - schema: wanxiang_english
  
  wanxiang_english:
    english_spacing: smart

Testing the Filter Logic

The capitalization behavior can be verified by examining how the filter processes candidates against input codes. When you type with specific casing patterns, the super_english module transforms the output accordingly:

  • Input code Hello world → Candidate becomes "Hello World"
  • Input code hELLO → Candidate becomes "HELLO" (when matching dictionary entries)

The filter applies these transformations in real-time during the candidate generation phase, before the text reaches your application.

Summary

  • Automatic capitalization for English input is implemented in the super_english.lua filter within the amzxyz/rime_wanxiang repository.
  • The feature activates automatically when using the wanxiang_english schema with any english_spacing mode except off.
  • The filter analyzes raw input codes using pattern matching (^%u%u for all caps, ^%u for initial cap) in the apply_segment_formatting() function.
  • Configuration requires adding wanxiang_english to your schema list and ensuring lua_filter@*super_english remains enabled in the pipeline.
  • No manual toggles are required; capitalization follows your typing pattern automatically.

Frequently Asked Questions

Do I need to manually switch between lowercase and uppercase modes?

No. The super_english.lua filter automatically detects your capitalization intent from the raw keystrokes. If you type the first letter as a capital, the output capitalizes the first letter; if you type the first two letters as capitals, the filter converts the entire word to uppercase. No mode switching or extra key combinations are necessary.

What happens if I type everything in lowercase?

When your raw input contains only lowercase letters, the filter preserves the lowercase format and does not force capitalization. The candidate appears exactly as defined in the dictionary without case transformation, allowing you to type casual lowercase text without interference from the auto-capitalization logic.

Can I disable automatic capitalization while keeping smart spacing?

No. In the current implementation within wanxiang_english.schema.yaml, the english_spacing option controls the entire super_english filter. Setting it to off disables both the spacing logic and the capitalization logic simultaneously. To disable only capitalization, you would need to modify the Lua code in super_english.lua to bypass the case transformation while preserving spacing rules.

Where is the capitalization logic implemented in the source code?

The core logic resides in wanxiang/lua/super_english.lua, specifically within the apply_segment_formatting() function. This file is referenced by wanxiang/wanxiang_english.schema.yaml through the lua_filter@*super_english declaration in the filters pipeline. The schema file acts as the configuration entry point, while the Lua file contains the pattern matching and string manipulation that performs the actual case conversion.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →