v2.0.0
Obsidian Vim Input Method Switch Plugin
English | 中文
An input method auto-switching plugin designed for Obsidian's Vim mode.
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
-
Download plugin to Obsidian plugins directory:
cd /path/to/your/vault/.obsidian/plugins/ git clone https://github.com/yourusername/vim-im-switch.git -
Enable plugin in Obsidian:
- Open Settings → Community Plugins
- Find "Vim Input Method Switch" and enable it
-
Configure input methods (optional):
- Set English input method (default:
com.apple.keylayout.ABC) - Set Chinese input method (default: auto-detect)
- Set English input method (default:
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 -nto get current input method name - Compares with configured Chinese/English input method names
Event Handling
- Keyboard events: Uses
capturemode 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 modeimStatus: Current input method state (Activate=Chinese, Deactivate=English)
Troubleshooting
Issue: Plugin not working
-
Check if fcitx-remote is properly installed:
which fcitx-remote fcitx-remote -n -
Check plugin logs (developer console):
- Press
Cmd+Option+I(macOS) orCtrl+Shift+I(Windows/Linux) to open developer console - Look for logs starting with
[VimIMSwitch]
- Press
-
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
- Confirm input method names in settings are correct
- Check logs in developer console after manually switching IM
- 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.sh
Debug
The plugin outputs key logs in the console:
🚀 Loading plugin...- Plugin loaded🔤 ESC → English- ESC switches to English🈳 → Chinese- Switch to Chinese❌ Error...- Error messages
Changelog
See CHANGELOG_en.md for detailed version history.
License
MIT License
Links
Description
众里寻她千百度的补丁,老问题,终于解决了。开心…………
为原生 Vim 和 Obsidian 编辑器 的 Vim 模式设计的智能输入法自动切换插件,包含:
Obsidian 插件:适用于 Obsidian 编辑器的 Vim 模式
Vim 插件:适用于原生 Vim/NeoVim 编辑器
跨平台支持:macOS、Linux、Windows 全平台兼容。macOS,其他平台未测试。windows vim本来就没有这个问题。
https://biboer.cn
v2.0.0
Latest
Languages
JavaScript
69.6%
TypeScript
11.1%
Vim Script
7.8%
Shell
6.6%
AutoHotkey
4.9%