2025-12-05 13:34:29 +08:00
2025-11-04 17:50:43 +08:00
2025-11-04 17:50:43 +08:00
2025-11-09 22:04:12 +08:00
2025-11-09 22:04:12 +08:00
2025-12-05 13:34:29 +08:00
2025-11-04 20:59:23 +08:00
2025-11-04 17:50:43 +08:00
2025-11-04 17:50:43 +08:00
2025-12-04 12:52:18 +08:00
2025-11-04 17:50:43 +08:00
2025-11-11 18:14:34 +08:00
2025-11-11 18:14:34 +08:00
2025-11-09 22:04:12 +08:00
2025-11-04 17:50:43 +08:00
2025-11-04 17:50:43 +08:00
2025-11-09 22:04:12 +08:00
2025-11-11 18:14:34 +08:00
2025-11-09 22:05:17 +08:00
2025-11-04 17:50:43 +08:00
2025-12-05 13:34:29 +08:00
2025-11-09 22:04:12 +08:00
2025-11-04 17:50:43 +08:00
2025-11-04 17:50:43 +08:00
2025-11-09 22:04:12 +08:00

Vim Input Method Switch Plugin

Version

English | 中文

An input method auto-switching plugin designed for Vim and Obsidian's Vim mode, including:

  • Obsidian Plugin: For Obsidian editor's Vim mode
  • Vim Plugin: For native Vim/NeoVim editors

Features

  • Automatic switching: Automatically switches input methods when transitioning between Vim's Normal and Insert modes
  • Smart memory: Remembers the input method state when exiting Insert mode and restores it on next entry
  • Seamless experience: Won't trigger input method changes during normal text input in Insert mode

Core Features

1. Mode Switch Automation

  • Enter Normal mode (press ESC or other commands) → Auto switch to English input method
  • Enter Insert mode (press i, a, o, etc.) → Auto restore previous input method state

2. Input Method State Memory

  • Automatically detects and saves current input method (Chinese/English) when exiting Insert mode
  • Automatically restores to last saved input method state when entering Insert mode
  • Supports mixed Chinese/English input scenarios

3. Smart Detection Mechanism

The plugin uses multiple detection mechanisms for reliability:

  • Keyboard event listening (primary): Uses capture mode to listen for ESC and Insert keys
  • CodeMirror events (auxiliary): Monitors vim-mode-change events
  • Polling (fallback): 100ms polling to detect mode changes

Quick Start

Requirements

macOS

brew install fcitx-remote-for-osx

Linux

# Ubuntu/Debian
sudo apt-get install fcitx

# Fedora
sudo dnf install fcitx

# Arch Linux
sudo pacman -S fcitx

Windows

Download fcitx-remote.exe and place it in your system PATH

Installation

Obsidian Plugin Installation

  1. Download plugin to Obsidian plugins directory:

    cd /path/to/your/vault/.obsidian/plugins/
    git clone https://github.com/yourusername/vim-im-switch.git
    
  2. Enable plugin in Obsidian:

    • Open Settings → Community Plugins
    • Find "Vim Input Method Switch" and enable it
  3. Configure input methods (optional):

    • Set English input method (default: com.apple.keylayout.ABC)
    • Set Chinese input method (default: auto-detect)

Vim Plugin Installation

  1. Copy plugin file to Vim config directory:

    mkdir -p ~/.vim/plugin
    cp fcitx-osx.vim ~/.vim/plugin/
    
  2. Restart Vim, the plugin will load automatically

  3. Configure input methods (optional): Add to .vimrc:

    " English input method ID (default)
    let g:fcitx_english_im = 'com.apple.keylayout.ABC'
    
    " Chinese input method ID (optional, auto-detect by default)
    " let g:fcitx_chinese_im = 'com.tencent.inputmethod.wetype.pinyin'
    

Deploy both plugins with a single command:

./deploy.sh

Note: v2.0.2 fixes a terminal-specific title/flash issue when using terminal Vim (see CHANGELOG for details).

Usage

Basic Usage Scenarios

Chinese Input:

Press i → Enter Insert mode → IM switches to Chinese (if last time was Chinese)
Type Chinese content
Press ESC → Exit to Normal mode → IM switches to English

English Input:

Press i → Enter Insert mode → IM stays English (if last time was English)
Type English content
Press ESC → Exit to Normal mode → IM stays English

Mixed Input:

Press i → Auto restore last IM
Type Chinese, then manually switch to English
Press ESC → Save current IM state (English)
Press i → Auto restore English IM

Supported Vim Commands

  • Enter Insert mode: i, I, a, A, o, O, s, S, c, C
  • Exit Insert mode: ESC, and other commands that trigger Normal mode

How It Works

graph TD
    A[Normal Mode<br/>English IM] -->|Press i/a/o etc| B[Detect Mode Change]
    B --> C[Restore Last Saved<br/>IM State]
    C --> D[Insert Mode<br/>Restored IM:<br/>Chinese/English]
    D -->|Press ESC| E[Save Current IM<br/>State CN/EN]
    E --> F[Switch to English IM]
    F --> A
    
    style A fill:#e1f5ff,stroke:#01579b,stroke-width:2px
    style D fill:#fff9c4,stroke:#f57f17,stroke-width:2px
    style E fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
    style F fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px

Technical Details

Input Method Detection

  • Uses fcitx-remote -n to get current input method name
  • Compares with configured Chinese/English input method names

Event Handling

  • Keyboard events: Uses capture mode to intercept keys early
  • Debouncing: Ignores repeated events within 100ms
  • Async processing: All input method switches are asynchronous and non-blocking

State Management

  • currentVimMode: Current Vim mode (normal/insert/visual)
  • lastInsertModeIMStatus: Last input method state in Insert mode
  • imStatus: Current input method state (Activate=Chinese, Deactivate=English)

Troubleshooting

Issue: Plugin not working

  1. Check if fcitx-remote is properly installed:

    which fcitx-remote
    fcitx-remote -n
    
  2. Check plugin logs (developer console):

    • Press Cmd+Option+I (macOS) or Ctrl+Shift+I (Windows/Linux) to open developer console
    • Look for logs starting with [VimIMSwitch]
  3. Verify input method names:

    # After switching to Chinese input method
    fcitx-remote -n
    # Output should match the Chinese IM name in plugin settings
    

Issue: Incorrect input method switching

  1. Confirm input method names in settings are correct
  2. Check logs in developer console after manually switching IM
  3. Check for conflicts with other plugins

Issue: ESC key requires multiple presses

  • This issue has been fixed in the latest version
  • If it still occurs, please update to the latest version

Development

Build

npm install
npm run build

Deploy

Deploy both Obsidian and Vim plugins with one command:

./deploy.sh

Debug

Obsidian Plugin

The plugin outputs key logs in the console:

  • Loading plugin... - Plugin loaded
  • ESC → English - ESC switches to English
  • → Chinese - Switches to Chinese
  • Error... - Error messages

Vim Plugin

View messages in Vim:

:messages
  • → Chinese - Switch to Chinese
  • Error... - Error messages

Changelog

See CHANGELOG_en.md for detailed version history.

License

MIT License

Description
众里寻她千百度的补丁,老问题,终于解决了。开心………… 为原生 Vim 和 Obsidian 编辑器 的 Vim 模式设计的智能输入法自动切换插件,包含: Obsidian 插件:适用于 Obsidian 编辑器的 Vim 模式 Vim 插件:适用于原生 Vim/NeoVim 编辑器 跨平台支持:macOS、Linux、Windows 全平台兼容。macOS,其他平台未测试。windows vim本来就没有这个问题。
https://biboer.cn
Readme 371 KiB
v2.0.0 Latest
2025-11-04 17:51:40 +08:00
Languages
JavaScript 69.6%
TypeScript 11.1%
Vim Script 7.8%
Shell 6.6%
AutoHotkey 4.9%