update at 2026-07-15 11:10:25

This commit is contained in:
douboer
2026-07-15 11:10:25 +08:00
parent aeade0f813
commit 0adb4b88c5
8 changed files with 402 additions and 523 deletions

View File

@@ -11,6 +11,27 @@
---
## [2.3.1] - 2026-07-15
### 改进
#### 原生 Vim 插件
- 将 macOS 原生 Vim 稳定方案更新为 Hammerspoon 优先:
- Normal / Esc 使用 `hs.keycodes.setLayout("ABC")`
- Insert 恢复中文时使用 `hs.keycodes.setMethod("Pinyin Simplified")`
- `im-select` 保留为 fallback。
- 修复 Apple 拼音可能出现“输入源显示中文但实际仍输入英文”的 layout/method 不一致问题。
- Insert 模式现在会记住同一 Vim 进程内上次使用的中文/英文状态。
- 记录跨 Vim 进程不持久记忆为已知限制。
- 清理原生 Vim 插件注释和命名,保留已验证稳定行为。
#### 文档
- 重写 README明确区分原生 Vim 插件和 Obsidian 插件。
-`README-im-select.md` 的 fallback 说明合并到 README并删除独立文档。
- 明确 Obsidian 插件逻辑不变,仍使用 `fcitx-remote`
---
## [2.0.3] - 2025-11-09
### 修复

View File

@@ -11,6 +11,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
---
## [2.3.1] - 2026-07-15
### Improved
#### Native Vim plugin
- Updated the stable macOS native Vim path to prefer Hammerspoon:
- Normal / Esc uses `hs.keycodes.setLayout("ABC")`.
- Insert Chinese restore uses `hs.keycodes.setMethod("Pinyin Simplified")`.
- `im-select` remains as fallback.
- Fixed the Apple Pinyin layout/method inconsistency where the input source could show Chinese while actual typing remained English.
- Insert mode now remembers the last Chinese/English state within the same Vim process.
- Documented cross-process Insert-state memory reset as a known limitation.
- Cleaned native Vim plugin comments and naming while preserving the validated behavior.
#### Documentation
- Rewrote README content to distinguish the native Vim plugin from the Obsidian plugin.
- Merged `README-im-select.md` fallback notes into README and removed the separate document.
- Clarified that the Obsidian plugin logic is unchanged and still uses `fcitx-remote`.
---
## [2.0.3] - 2025-11-09
### Fixed

View File

@@ -1,118 +1,87 @@
# 项目文件对比
# 项目实现对比
## 新增文件(使用 im-select 版本)
本项目当前包含两套相关但独立的输入法切换实现:
| 文件 | 大小 | 说明 |
|--------|------|------|
| `vim-im-switch-select.vim` | 4.5KB | 主插件文件(使用 im-select |
| `test-im-select.sh` | 2.2KB | 自动化测试脚本 |
| `run-vim-test.sh` | 665B | Vim 交互测试脚本 |
| `test-im-switch.txt` | 316B | 测试文件 |
| `README-im-select.md` | 5.8KB | 详细说明文档 |
| 实现 | 文件 | 当前角色 | 主要切换方式 |
|---|---|---|---|
| 原生 Vim 插件 | `vim-im-switch-select.vim` | 当前 macOS 原生 Vim 稳定方案 | Hammerspoon 优先,`im-select` fallback |
| Obsidian 插件 | `main.ts` | Obsidian Vim keymap 输入法切换 | `fcitx-remote` |
## 核心差异对比
## 原生 Vim 插件
### vim-im-switch.vim (原版 - fcitx-remote)
`vim-im-switch-select.vim` 面向 macOS 原生 Vim。
```vim
" 使用 fcitx-remote
executable("fcitx-remote")
system("fcitx-remote -n")
fcitx-remote -s <IM_ID>
当前稳定策略:
" 变量和函数
g:fcitx_*
Fcitx*()
- Normal / Esc切到英文 `ABC`
- Insert恢复同一 Vim 进程内上次 Insert 使用的中/英状态。
- 首次进入 Insert 默认中文。
- 优先使用 Hammerspoon
```lua
hs.keycodes.setLayout("ABC")
hs.keycodes.setMethod("Pinyin Simplified")
```
- 当 `hs` 不可用时fallback 到 `im-select`
```bash
im-select com.apple.keylayout.ABC
im-select com.apple.inputmethod.SCIM.ITABC
```
### 为什么不再只依赖 im-select
`im-select` 只能切换 macOS input source ID。Apple 拼音可能出现以下不一致状态:
```text
sourceID = com.apple.inputmethod.SCIM.ITABC
layout = ABC
method = Pinyin Simplified
```
### vim-im-switch-select.vim (新版 - im-select)
表现为菜单栏显示中文输入法,但实际仍输入英文。
```vim
" 使用 im-select
executable("im-select")
system("im-select")
im-select <IM_ID>
Hammerspoon 的 `setLayout()` / `setMethod()` 能直接设置 layout / method因此是当前主路径。
" 变量和函数
g:imselect_*
IMSelect*()
```
## Obsidian 插件
## 功能完全一致
`main.ts` 是 Obsidian 插件入口。本次 Hammerspoon 方案没有改造 Obsidian 插件。
✅ 自动切换输入法
✅ 智能状态记忆
✅ 异步处理
✅ 中英混合友好
✅ 多光标支持
✅ 防抖机制
当前 Obsidian 插件仍然:
## 测试验证
- 使用 `fcitx-remote` 查询和切换输入法。
- 监听 Obsidian / CodeMirror Vim 模式变化。
- Normal / Visual 模式切英文。
- Insert / Replace 模式恢复上次 Insert 状态。
- 通过插件设置页配置不同平台的 `fcitx-remote` 路径。
### 1. im-select 基础功能测试
```bash
./test-im-select.sh
```
结果:✅ 所有测试通过
- ✓ im-select 可执行
- ✓ 获取当前输入法
- ✓ 切换到英文
- ✓ 恢复原输入法
- ✓ 插件文件完整9个函数
## 行为对比
### 2. Vim 插件集成测试
```bash
./run-vim-test.sh
```
手动测试步骤:
1. 进入 Insert 模式 → 输入法状态保持
2. 切换到中文输入 → 输入中文内容
3. ESC 退出 → 自动切换到英文
4. 再次 i 进入 → 自动恢复中文输入法
| 场景 | 原生 Vim 插件 | Obsidian 插件 |
|---|---|---|
| Normal / Esc | Hammerspoon `setLayout("ABC")`fallback `im-select` | `fcitx-remote -s <English IM>` |
| Insert 中文恢复 | Hammerspoon `setMethod("Pinyin Simplified")`fallback `im-select` | `fcitx-remote -s <Chinese IM>` |
| Insert 状态记忆 | 同一 Vim 进程内有效 | Obsidian 插件运行期间有效 |
| 跨进程/重启持久化 | 不持久化 | 由 Obsidian 插件运行状态决定 |
| 最近 Hammerspoon 调整影响 | 是 | 否 |
## 使用建议
## 主要文件
### 场景 1macOS 用户,已安装 fcitx-remote-for-osx
- 使用 `vim-im-switch.vim`(原版)
### 场景 2macOS 用户,使用 im-select
- 使用 `vim-im-switch-select.vim`(新版)
### 场景 3Linux 用户
- 使用 `vim-im-switch.vim`(原版,配合 fcitx
### 场景 4想要更轻量的方案
- 使用 `vim-im-switch-select.vim`
- 项目已包含 im-select 可执行文件
- 无需额外安装 fcitx-remote
## 安装方法
```bash
# 方法 1复制到 Vim 插件目录
cp vim-im-switch-select.vim ~/.vim/plugin/
# 方法 2在 .vimrc 中 source
echo "source $(pwd)/vim-im-switch-select.vim" >> ~/.vimrc
# 方法 3确保 im-select 在 PATH 中
sudo cp im-select /usr/local/bin/
chmod +x /usr/local/bin/im-select
```
## 配置示例
```vim
" 在 .vimrc 中添加
let g:imselect_english_im = 'com.apple.keylayout.ABC'
let g:imselect_chinese_im = 'com.apple.inputmethod.SCIM.ITABC'
```
| 文件 | 说明 |
|---|---|
| `vim-im-switch-select.vim` | 当前原生 Vim 稳定插件 |
| `main.ts` | Obsidian 插件入口 |
| `README.md` | 中文说明文档 |
| `README_en.md` | English documentation |
| `CHANGELOG.md` / `CHANGELOG_en.md` | 更新日志 |
| `RELEASE.md` | 发布说明 |
## 总结
**vim-im-switch-select.vim 已创建成功**
**逻辑与原版完全相同**
**所有测试通过**
**文档齐全**
当前推荐:
可以立即投入使用!
- 原生 Vim使用 `vim-im-switch-select.vim`Hammerspoon 优先,`im-select` fallback。
- Obsidian继续使用现有 `main.ts` 插件逻辑,保持 `fcitx-remote` 路径。
两者目标相同,但实现路径不同;不要把原生 Vim 的 Hammerspoon 调整误认为 Obsidian 插件也已改造。

View File

@@ -241,8 +241,12 @@ Insert 中切到英文 -> Esc -> 再 Insert -> 英文
| 文件 | 说明 |
|---|---|
| `vim-im-switch-select.vim` | 当前原生 Vim 稳定插件 |
| `README.md` | 当前说明文档 |
| `main.ts` | Obsidian 插件入口 |
| `README.md` | 中文说明文档 |
| `README_en.md` | English documentation |
| `CHANGELOG.md` / `CHANGELOG_en.md` | 更新日志 |
| `COMPARISON.md` | 原生 Vim 插件与 Obsidian 插件对比 |
| `RELEASE.md` | 发布说明 |
## 故障排除

View File

@@ -1,241 +1,257 @@
# Vim Input Method Switch Plugin
[![Version](https://img.shields.io/badge/version-2.0.3-blue.svg)](./CHANGELOG.md)
English | [中文](./README.md)
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
This repository contains two related but currently separate implementations:
## Features
- **Native Vim plugin**: `vim-im-switch-select.vim`, currently the stable macOS path.
- **Obsidian plugin**: `main.ts`, unchanged by the recent Hammerspoon work.
- **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
## Native Vim plugin
## Core Features
The native Vim plugin is designed for macOS Vim and uses this stable strategy:
### 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
- Normal mode always switches to English `ABC`.
- Insert mode restores the last Chinese/English state used in the same Vim process.
- Hammerspoon is preferred via `hs.keycodes.setLayout()` / `hs.keycodes.setMethod()`.
- `im-select` is kept only as fallback.
### 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
> Note: The Hammerspoon behavior described here applies only to the native Vim plugin `vim-im-switch-select.vim`. It does not change the Obsidian plugin.
### 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
### Mode behavior
## Quick Start
| Vim state | Behavior |
|---|---|
| After Vim starts | Delayed switch to English `ABC` |
| Enter Insert | Restore the last Insert-mode Chinese/English state in this Vim process; first entry defaults to Chinese |
| Leave Insert / `Esc` | Save the current Insert-mode language state, then switch to English `ABC` |
### Requirements
Example:
```text
First Insert -> Chinese
Manually switch to English in Insert -> Esc -> next Insert -> English
Manually switch back to Chinese in Insert -> Esc -> next Insert -> Chinese
Quit Vim and open again -> memory resets; first Insert defaults to Chinese
```
### Why Hammerspoon
Using only `im-select` can leave Apple Pinyin in an inconsistent macOS state:
```text
sourceID = com.apple.inputmethod.SCIM.ITABC
layout = ABC
method = Pinyin Simplified
```
The menu bar may show Chinese input, but actual typing remains English.
Hammerspoon can directly set layout and method:
```lua
hs.keycodes.setLayout("ABC")
hs.keycodes.setMethod("Pinyin Simplified")
```
This avoids relying only on the input source ID.
### Hammerspoon setup
Install and run Hammerspoon. Enable IPC in `~/.hammerspoon/init.lua`:
```lua
require("hs.ipc")
hs.ipc.cliInstall()
```
Reload Hammerspoon config, then verify:
#### macOS
```bash
brew install fcitx-remote-for-osx
hs -c 'hs.keycodes.setLayout("ABC")'
hs -c 'hs.keycodes.setMethod("Pinyin Simplified")'
```
#### Linux
Both commands should return:
```text
true
```
### im-select fallback
If `hs` is unavailable, the Vim plugin falls back to `im-select`:
```bash
# Ubuntu/Debian
sudo apt-get install fcitx
# Fedora
sudo dnf install fcitx
# Arch Linux
sudo pacman -S fcitx
im-select
im-select com.apple.keylayout.ABC
im-select com.apple.inputmethod.SCIM.ITABC
```
#### Windows
Download [fcitx-remote.exe](https://github.com/yuanotes/obsidian-vim-im-switch-plugin/releases/download/1.0.3/fcitx-remote.exe) and place it in your system PATH
Common input source IDs:
### Installation
| Input method | ID |
|---|---|
| ABC | `com.apple.keylayout.ABC` |
| Apple Simplified Pinyin | `com.apple.inputmethod.SCIM.ITABC` |
#### Obsidian Plugin Installation
### Install native Vim plugin
1. Download plugin to Obsidian plugins directory:
```bash
cd /path/to/your/vault/.obsidian/plugins/
git clone https://github.com/yourusername/vim-im-switch.git
```
Copy the plugin to Vim's plugin directory:
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:
```bash
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`:
```vim
" 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'
```
#### One-Click Deploy (Recommended)
Deploy both plugins with a single command:
```bash
./deploy.sh
mkdir -p ~/.vim/plugin
cp vim-im-switch-select.vim ~/.vim/plugin/
```
Note: v2.0.2 fixes a terminal-specific title/flash issue when using terminal Vim (see CHANGELOG for details).
Or source it from `.vimrc`:
## 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
```vim
source /path/to/vim-im-switch-select.vim
```
**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
### Native Vim configuration
Defaults are for macOS ABC + Apple Simplified Pinyin:
```vim
" Hammerspoon path: English keyboard layout name
let g:imselect_hs_english_layout = 'ABC'
" Hammerspoon path: Chinese input method name
let g:imselect_hs_chinese_method = 'Pinyin Simplified'
" im-select fallback: English input source ID
let g:imselect_english_im = 'com.apple.keylayout.ABC'
" im-select fallback: Chinese input source ID
let g:imselect_chinese_im = 'com.apple.inputmethod.SCIM.ITABC'
" Delay before restoring Insert state, default 80ms
let g:imselect_restore_delay = 80
" Confirm target state after restore, default 200ms
let g:imselect_confirm_delay = 200
```
**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
### Native Vim implementation notes
```vim
InsertLeavePre -> Save the last Insert-mode Chinese/English state
InsertLeave -> Switch to English ABC
InsertEnter -> Delayed restore of the last Insert-mode state
VimEnter -> Delayed switch to English ABC on startup
```
### Supported Vim Commands
Important details:
- **Enter Insert mode**: `i`, `I`, `a`, `A`, `o`, `O`, `s`, `S`, `c`, `C`
- **Exit Insert mode**: `ESC`, and other commands that trigger Normal mode
- `InsertLeavePre` must save state before `InsertLeave` switches to English.
- Timer callbacks check the target state so fast `i<Esc>` does not switch Normal mode back to Chinese.
- Hammerspoon is the primary path; `im-select` is fallback only.
- State memory is script-local and only valid within the current Vim process.
## How It Works
### Native Vim manual test
```mermaid
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
1. Open Vim:
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:
```bash
which fcitx-remote
fcitx-remote -n
vim test-im-switch.txt
```
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]`
2. First `i`: should switch to Chinese.
3. Type Chinese, press `Esc`: should switch to English `ABC`.
4. Press `i` again: should restore Chinese.
5. In Insert, manually switch to English, type English, press `Esc`.
6. Press `i` again: should restore English.
7. In Insert, manually switch back to Chinese, press `Esc`, then `i`: should restore Chinese.
8. Quit and reopen Vim: first Insert defaults to Chinese; this is a known limitation.
3. Verify input method names:
```bash
# After switching to Chinese input method
fcitx-remote -n
# Output should match the Chinese IM name in plugin settings
```
### Native Vim verification
### 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
```bash
vim -Nu NONE -n -es -S "/path/to/vim-im-switch-select.vim" -c 'qa'
```
### 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
```bash
hs -c 'hs.keycodes.setLayout("ABC")'
hs -c 'hs.keycodes.setMethod("Pinyin Simplified")'
```
## Development
## Obsidian plugin
The Obsidian plugin remains in this repository and is implemented by `main.ts`.
Current Obsidian plugin behavior is unchanged:
- Uses `fcitx-remote` to query and switch input methods.
- Listens to Obsidian / CodeMirror Vim mode changes.
- Normal / Visual mode switches to English.
- Insert / Replace mode restores the last Insert-mode state.
- Settings still use the plugin settings page and the configured `fcitx-remote` paths / input method IDs.
### Obsidian requirements
The plugin expects a working `fcitx-remote` command for the current platform.
Default macOS path:
```text
/usr/local/bin/fcitx-remote
```
Default input methods:
```text
English: com.apple.keylayout.ABC
Chinese: auto-detect, fallback com.apple.inputmethod.SCIM.ITABC
```
### Obsidian development
### Build
```bash
npm install
npm run build
```
### Deploy
Deploy both Obsidian and Vim plugins with one command:
```bash
./deploy.sh
## Known limitations
### Native Vim Insert memory is not persisted across Vim processes
The native Vim plugin only remembers the last Insert-mode state within the current Vim process.
```text
Switch to English in Insert -> Esc -> next Insert -> English
Quit Vim -> reopen Vim -> first Insert defaults to Chinese
```
### Debug
This is intentional for now; no file-based persistence is implemented.
#### 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
### Native Vim depends on Hammerspoon for the stable macOS path
#### Vim Plugin
View messages in Vim:
```vim
:messages
```
- `→ Chinese` - Switch to Chinese
- `Error...` - Error messages
The stable path requires:
### Changelog
- Hammerspoon running
- `hs` CLI available
- `hs.ipc` enabled
- Input method name matching `Pinyin Simplified`
See [CHANGELOG_en.md](./CHANGELOG_en.md) for detailed version history.
If Hammerspoon is unavailable, the plugin falls back to `im-select`, but fallback cannot fully fix Apple Pinyin layout/method inconsistency.
### No simulated CapsLock / Ctrl-Space
The native Vim plugin does not simulate `Caps Lock`, `Ctrl-Space`, `Shift`, or other system shortcuts. Those keys may be received by Vim and cause side effects.
## Main files
| File | Description |
|---|---|
| `vim-im-switch-select.vim` | Current stable native Vim plugin |
| `main.ts` | Obsidian plugin entry |
| `README.md` | Chinese documentation |
| `README_en.md` | English documentation |
| `CHANGELOG.md` / `CHANGELOG_en.md` | Change history |
| `RELEASE.md` | Release notes |
## License
MIT License
## Links
- [Changelog](./CHANGELOG_en.md)
- [中文文档](./README.md)
- [fcitx-remote-for-osx](https://github.com/xcodebuild/fcitx-remote-for-osx)

View File

@@ -4,219 +4,95 @@
---
## v2.3.1 - 2026-07-15
### 原生 Vim 插件Hammerspoon 稳定方案
本版本更新的是原生 Vim 插件 `vim-im-switch-select.vim`。Obsidian 插件逻辑不变。
#### 改进
- macOS 原生 Vim 插件改为 Hammerspoon 优先:
- Normal / Esc 使用 `hs.keycodes.setLayout("ABC")` 切到英文。
- Insert 恢复中文时使用 `hs.keycodes.setMethod("Pinyin Simplified")`
- `im-select` 仅作为 fallback。
- 修复 Apple 拼音可能出现的状态不一致问题:
```text
sourceID = com.apple.inputmethod.SCIM.ITABC
layout = ABC
method = Pinyin Simplified
```
该状态下菜单栏可能显示中文,但实际仍输入英文。
- Insert 模式支持同一 Vim 进程内状态记忆:
- Insert 中使用中文,`Esc` 后再进入 Insert 恢复中文。
- Insert 中手动切英文,`Esc` 后再进入 Insert 恢复英文。
- 记录已知限制:退出 Vim 后状态不持久化,重新打开 Vim 后首次 Insert 默认中文。
#### 文档
- 重写 README明确当前稳定策略。
- 补充 Obsidian 插件说明:仍使用 `fcitx-remote`,未改为 Hammerspoon。
- 合并 `README-im-select.md` 内容到 README并删除独立文档。
- 更新中英文 README、CHANGELOG、COMPARISON 和 RELEASE。
---
## v2.0.3 - 2025-11-09
### 修复 Normal 模式下按 ESC 触发输入法切换的问题
#### Obsidian 插件
- 修复 Normal 模式下按 ESC 会意外触发输入法切换的问题。
- 只在 Insert 或 Replace 模式下按 ESC 时保存输入法状态并切换到英文。
- Normal 模式下按 ESC 不再改变输入法。
---
## v2.0.2 - 2025-11-04
### 终端兼容性修复
- 修复在 macOS 终端 Vim 中按 ESC 时,子进程输出导致标题栏短暂闪烁的问题。
- 使用更通用的后台静默执行方式替代不兼容的 `job_start(..., {'detach': v:true})`。
---
## v2.0.0 - 2025-11-04
### 新增 Vim 原生插件支持
- 新增原生 Vim 插件支持。
- 支持 Normal / Insert 模式输入法自动切换。
- 支持 Insert 模式输入法状态记忆。
- 增加 Vim 插件安装、配置和调试说明。
---
## v1.0.8 - 2025-01-04
### Obsidian 插件输入法状态记忆
- Obsidian 插件记住退出 Insert 模式时使用的输入法。
- 下次进入 Insert 模式时恢复上次保存的输入法状态。
- 修复首次 ESC 不切英文、Insert 模式正常输入被误触发等问题。
---
## v1.0.0 - 2024-06-01
### 首次发布
- 基本的 Vim 模式输入法自动切换功能
- 支持 macOS 系统
- 支持 Normal/Insert 模式切换
- 基本的 Vim 模式输入法自动切换功能
- 支持 macOS
- 支持 Normal / Insert 模式切换
---
## v1.0.1 - 2024-06-20
### Bug 修复
- 修复了插件加载失败的问题
- 改进了兼容性
---
## v1.0.2 - 2024-07-15
### 性能优化
- 优化了输入法切换的响应时间
- 减少了不必要的命令调用
---
## v1.0.3 - 2024-08-01
### Bug 修复
- 修复了初始化时的异步问题
- 改进了命令执行的错误处理
---
## v1.0.4 - 2024-09-05
### 新增功能
- 添加了对 Linux 系统的支持
- 改进了日志输出格式
---
## v1.0.5 - 2024-10-10
### Bug 修复
- 修复了 Windows 系统下的兼容性问题
- 改进了错误处理逻辑
---
## v1.0.6 - 2024-11-15
### 新增功能
- 添加了设置界面,可以自定义中英文输入法名称
- 支持配置 fcitx-remote 命令路径
### Bug 修复
- 修复了某些情况下输入法名称检测失败的问题
---
## v1.0.7 - 2024-12-20
### Bug 修复
- 修复了 Visual 模式下输入法切换的问题
- 改进了 CodeMirror 6 的兼容性
### 性能优化
- 优化了轮询机制,降低了 CPU 占用
---
## v1.0.8 - 2025-01-04
### 重大更新:输入法状态记忆功能
#### 新增功能
**输入法状态记忆**
- 智能记忆上次输入法状态:插件现在会记住你退出 Insert 模式时使用的输入法(中文/英文)
- 自动恢复:下次进入 Insert 模式时,自动恢复到上次保存的输入法状态
- 支持中英文混合输入场景
**状态管理增强**
- 新增 `lastInsertModeIMStatus` 变量追踪上次 Insert 模式的输入法状态
- 在退出 Insert 模式时,实时检测并保存当前输入法名称
- 在进入 Insert 模式时,根据保存的状态决定是否切换输入法
#### Bug 修复
**修复 ESC 键第一次按下无效的问题**
- 问题:用户首次按下 ESC 键时,输入法不会切换到英文,需要按第二次才生效
- 解决:将键盘事件监听器注册移到 `onload()` 方法中,使用事件捕获模式(`{ capture: true }`
- 效果:现在第一次按 ESC 就能立即切换到英文输入法
**修复 Insert 模式下输入字符触发输入法切换**
- 问题:在 Insert 模式下正常输入文本时,输入 `i`, `a`, `o` 等字符会意外触发输入法切换
- 解决:在 Insert 按键监听器中添加模式检查:`if (this.currentVimMode !== 'normal') return;`
- 效果:在 Insert 模式下正常输入文本不会被干扰
#### 性能优化
**使用事件捕获模式提高响应速度**
- 使用 `addEventListener('keydown', handler, { capture: true })` 代替默认的冒泡模式
- 在事件处理链的最早阶段捕获按键
- ESC 键响应更快,几乎没有延迟
**优化输入法检测逻辑**
- 在 ESC 键处理时,先检测当前输入法再决定是否切换
- 避免不必要的 `fcitx-remote` 调用
- 当前已经是英文输入法时,不会重复切换
#### 技术改进
**多重检测机制**
1. 键盘事件监听(主要)- 使用 capture 模式监听 ESC 和 Insert 按键
2. CodeMirror 事件监听(辅助)- 监听 vim-mode-change 事件
3. 定时轮询(兜底)- 每 100ms 检查一次 Vim 模式
---
## v2.0.0 - 2025-11-04
### 重大更新:新增 Vim 原生插件支持
#### 新增功能
**Vim 原生插件支持**
- 新增 fcitx-osx.vim 插件:为原生 Vim/NeoVim 编辑器提供输入法自动切换功能
- 智能输入法状态记忆:
- 记住退出 Insert 模式时的输入法(中文/英文)
- 下次进入 Insert 模式时自动恢复上次的输入法状态
- 完全无感知切换,无任何 UI 闪烁
- 使用 fcitx-remote -s 命令:
- 通过指定输入法 ID 进行精确切换
- 替代原有的 `-c`/`-o` 开关命令
- 支持自定义英文和中文输入法 ID
- 异步执行优化:
- 使用 Vim 8+ 的 `job_start()` 异步执行命令
- 完全消除输入法切换时的 UI 闪烁和延迟
- 向后兼容旧版本 Vim使用后台进程
**部署脚本增强**
- deploy.sh 更新:一键部署 Obsidian 插件和 Vim 插件
- 自动创建 `~/.vim/plugin/` 目录
- 同时复制两个插件到各自的目标位置
#### 改进
**Vim 插件性能优化**
- 使用 `fcitx-remote -n` 获取当前输入法名称
- 保存完整的输入法 ID 而不是简单的开关状态
- 避免不必要的输入法切换(相同输入法时跳过)
- 所有输出重定向到 `/dev/null`,确保静默执行
#### Bug 修复
- 修复 Vim 插件中 `fcitx-remote -c` 命令不生效的问题
- 修复标题栏显示 "fcitx-remote" 的闪烁问题
- 修复字符串比较失败(`"2\n" == 2`)的问题
#### 文档更新
- 更新 README.md 和 README_en.md添加 Vim 插件安装说明
- 更新所有文档标题,从 "Obsidian" 改为包含两个插件的描述
- 添加 Vim 插件配置说明和调试方法
---
## v2.0.2
2025-11-04
### 修复
**终端兼容性修复**
- 修复在 macOS 终端vi/vim中按 ESC 时,子进程输出导致标题栏短暂闪烁的问题
- 使用 nohup/background 方式彻底静默化命令执行
- 移除 `job_start(..., {'detach': v:true})` 不兼容选项,改以更通用的后台执行方式
### 文档
- 补充 RELEASE/README 中关于终端下行为的说明
---
## v2.0.3
2025-11-09
**修复 Normal 模式下按 ESC 触发输入法切换的问题**
### 修复
**Obsidian 插件**
- **修复 Normal 模式下按 ESC 触发输入法切换的问题**
- 问题:在 Normal 模式下按 ESC 会意外触发输入法切换(从中文切到英文,再按又从英文切到英文)
- 原因:`handleKeyDown` 函数处理 ESC 键时没有检查当前 Vim 模式
- 解决:增加模式检查,只在 Insert 或 Replace 模式下按 ESC 时才保存输入法状态并切换到英文
- 效果:与原生 Vim 插件行为保持一致Normal 模式下按 ESC 不会改变输入法
### 改进
- 提高了模式检测的准确性
- 优化了 ESC 键的处理逻辑
---
**查看详细更新日志**: [CHANGELOG.md](./CHANGELOG.md) | [CHANGELOG_en.md](./CHANGELOG_en.md)
详细历史见:
- [CHANGELOG.md](./CHANGELOG.md)
- [CHANGELOG_en.md](./CHANGELOG_en.md)

View File

@@ -1,18 +0,0 @@
#!/bin/bash
# 在 Vim 中测试插件
echo "正在启动 Vim 测试 vim-im-switch-select.vim 插件..."
echo "说明:"
echo " 1. 按 i 进入 Insert 模式"
echo " 2. 切换到中文输入法并输入一些中文"
echo " 3. 按 ESC 退出到 Normal 模式(输入法应该切换到英文)"
echo " 4. 再按 i 进入 Insert 模式(输入法应该自动恢复到中文)"
echo " 5. 按 :q! 退出测试"
echo ""
echo "按 Enter 继续..."
read
# 使用绝对路径加载插件
vim -c "source /Users/gavin/vim-im-switch/vim-im-switch-select.vim" \
-c "echo '插件已加载,按 i 开始测试'" \
/Users/gavin/vim-im-switch/test-im-switch.txt

26
t.md
View File

@@ -1,21 +1,11 @@
# 临时测试记录
jkfsd
及开发京东上看
开接口饭店司机
可激发卡的接口
福建省多孔菌科
及开发水电接口
激发开水大家
空间饭店
jkfd
kjfd
开娇娇饭店
kjfdk
空间发快递
jfdk
kj
激发开水大家看
该文件是临时 Markdown 测试文件,不属于插件正式文档。
正式说明请阅读:
- [README.md](./README.md)
- [README_en.md](./README_en.md)
- [COMPARISON.md](./COMPARISON.md)
- [CHANGELOG.md](./CHANGELOG.md)
- [RELEASE.md](./RELEASE.md)