# How English Input Mode Integrates with Chinese Input in Rime Wanxiang

> Discover how Rime Wanxiang seamlessly integrates English input with Chinese typing using a dedicated schema and Lua filter for efficient bilingual text processing.

- Repository: [amzxyz/rime_wanxiang](https://github.com/amzxyz/rime_wanxiang)
- Tags: deep-dive
- Published: 2026-02-24

---

**The wanxiang schema achieves seamless bilingual typing by routing English input through a dedicated schema while the [`super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/super_english.lua) filter formats and spaces text before it re-enters the Chinese processing pipeline.**

The Rime wanxiang input method allows users to compose mixed-language sentences without manual mode switching or application changes. This capability stems from a three-layer integration architecture defined across [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml), [`wanxiang_english.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_english.schema.yaml), and [`lua/super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/super_english.lua). The system treats English not as an isolated mode but as a stream that temporarily bypasses Chinese segmentation yet returns to the same candidate processing pipeline.

## Scheme-Level Language Switching

The foundation of bilingual input rests on the `ascii_mode` switch declared in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml):

```yaml
switches:
  - name: ascii_mode          # 中英输入状态

    states: [ 中文, 英文 ]

```

When activated (typically via `Shift+Space` as bound in the `key_binder` section), this switch instructs the Rime engine to treat incoming keystrokes as raw ASCII rather than pinyin. The [`super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/super_english.lua) filter reads this state during its `init()` function to load English-specific configurations:

```lua
env.english_spacing_mode = cfg:get_string("wanxiang_english/english_spacing") or "off"
env.spacing_timeout       = cfg:get_double("wanxiang_english/spacing_timeout") or 0

```

This initialization ensures that spacing rules and formatting options activate only when `ascii_mode` is set to "英文".

## The English Schema and Dictionary Layer

The dedicated [`wanxiang_english.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_english.schema.yaml) defines the English processing environment and references the flat dictionary file [`wanxiang_english.dict.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_english.dict.yaml). This schema configures:

```yaml
wanxiang_english:
  dictionary: wanxiang_english
  enable_completion: true
  enable_sentence: true
  english_spacing: smart
  spacing_timeout: 5

```

Setting `enable_sentence: true` allows the **super_english** filter to treat complete English phrases as single candidates rather than forcing per-word completion. The dictionary provides raw vocabulary, while the schema parameters control how English text behaves when mixed with Chinese input.

## The Super-English Filter: Bridging Both Languages

The [`lua/super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/super_english.lua) file functions as a **Lua filter** positioned early in the processing chain—after segmentors but before Chinese-specific filters like `super_lookup` and `super_comment`. This positioning allows it to format English text while preserving downstream Chinese processing capabilities.

### Detecting English Candidates

The filter identifies English input by checking `is_ascii_phrase_fast(text)` and verifying the presence of letters via `has_letters`. When `ascii_mode` is active, incoming ASCII characters route through the English dictionary first, producing raw candidates that super_english intercepts before they reach Chinese-oriented filters.

### Smart Spacing and Capitalization

The filter maintains state across commits using `prev_commit_is_eng` and timestamp tracking (`last_commit_time`). In **smart spacing** mode (the default), it automatically inserts spaces between consecutive English words while respecting the `spacing_timeout` threshold:

```lua
if mode == "smart" then
    if code_ctx.prev_is_eng then
        if not find(text, "^%s") then text = " " .. text end
    end
end

```

The `apply_segment_formatting` function handles capitalization based on raw input codes, preserving user intent when typing mixed-case strings like "hELLo". The filter also normalizes non-ASCII spaces (such as NBSP) to standard spaces.

### Preserving the Chinese Processing Pipeline

After formatting English segments, the filter returns candidates to the pipeline where Chinese-specific processors can still operate. For mixed input like "你好hello", the Chinese segment "你好" passes through unchanged while "hello" receives English formatting. Both segments then continue to filters such as `super_lookup` (for reverse lookup) and `super_comment` (for tone hints), which may append metadata without altering the formatted English text.

The filter maintains a short **sticky buffer** (`STICKY_BUFFER_SIZE = 2`) to handle backspacing across language boundaries, ensuring that deleting the English portion of a mixed candidate does not destroy the Chinese context.

## Configuration and Usage Examples

### Toggling Input Modes

Bind the mode switch in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml):

```yaml
key_binder:
  bindings:
    - { when: always, accept: Shift+space, select: .next }

```

Pressing `Shift+Space` cycles to the next schema state, toggling `ascii_mode` between Chinese and English.

### Mixed Input Behavior

Input sequence:
1. Type "你好" in Chinese mode
2. Toggle to English mode
3. Type "hello world"

Result: "你好 hello world" with automatic spacing inserted by [`super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/super_english.lua) only between the English words.

### Timeout-Controlled Spacing

With `spacing_timeout: 5`, pausing longer than 5 seconds between English words resets the `prev_commit_is_eng` flag. Subsequent English input will not receive automatic leading spaces, preventing unwanted spacing when resuming typing after a break.

## Summary

- **Scheme switching**: The `ascii_mode` switch in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml) toggles between Chinese and English input states, triggering the ASCII composer when active.
- **Dedicated English layer**: [`wanxiang_english.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_english.schema.yaml) and its dictionary provide isolated vocabulary and configuration options for English candidates.
- **Integration filter**: [`lua/super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/super_english.lua) detects English text, applies smart spacing and capitalization, and reinserts formatted candidates into the Chinese processing pipeline.
- **State management**: The filter tracks previous commits and timing to enable intelligent spacing while maintaining a sticky buffer for seamless backspacing across language boundaries.
- **Pipeline compatibility**: English formatting occurs before Chinese filters like `super_lookup` and `super_comment`, ensuring mixed sentences receive appropriate annotations without formatting loss.

## Frequently Asked Questions

### How do I toggle between English and Chinese input modes?

Press `Shift+Space` (or your configured `key_binder` shortcut) to cycle the `ascii_mode` switch defined in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml). This changes the input stream from pinyin to raw ASCII and activates the English formatting filters.

### What is the "smart spacing" feature in mixed input?

Smart spacing automatically inserts a single space between consecutive English words while suppressing spaces after Chinese characters or punctuation. The [`super_english.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/super_english.lua) filter tracks `prev_commit_is_eng` and respects the `spacing_timeout` setting (default 5 seconds) to determine when to insert these automatic spaces.

### Can I customize the English vocabulary in wanxiang?

Yes. Edit [`wanxiang_english.dict.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_english.dict.yaml) to add or remove words from the flat dictionary list. The [`wanxiang_english.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_english.schema.yaml) controls completion behavior and spacing rules, allowing you to tune how aggressively the system suggests English words alongside Chinese input.

### Why does my English text lose formatting when mixed with Chinese?

This typically occurs if the `super_english` filter is mispositioned in the `filters` list of [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml). The filter must run **before** Chinese-specific filters like `super_lookup` but **after** segmentors. Verify that `lua_filter@super_english` appears in the correct sequence to ensure English formatting persists through the entire pipeline.