smart-ime.nvim is a lightweight per-buffer IME switching plugin for Neovim on Windows.
It automatically switches your input method to English when leaving Insert mode,
and restores the previous state when re-entering — all without any external binaries.
- ✨ Features
- 📦 Installation
- 🔧 Configuration
- 🔑 switch_key
- 💡 Examples
- ❓ FAQ
- 📣 Self-Promotion
- 💬 Feedback
- 🙏 Credits
- 📄 License
- Per-buffer IME state - Each buffer remembers its own input method state
- Automatic switching - English on
InsertLeave, restore onInsertEnter - Focus normalization - Ensures consistent IME state when Neovim regains focus
- Zero dependencies - No
im-selector other external binaries needed - Async & non-blocking - Uses
vim.system()for all PowerShell calls - Optional logging - Integrates with logger.nvim when available
- No background polling - Reacts only to editor events
smart-ime.nvim works with all major Neovim plugin managers. Neovim 0.10+ and Windows with PowerShell are required.
-
Using nvim-plug
require('plug').add({ { 'wsdjeg/smart-ime.nvim', }, })
-
Using lazy.nvim
{ 'wsdjeg/smart-ime.nvim', event = 'InsertEnter', opts = {}, } -
Using packer.nvim
use({ 'wsdjeg/smart-ime.nvim', config = function() require('smart-ime').setup({}) end, })
-
Using luarocks
luarocks install smart-ime.nvim
This example shows a basic setup for smart-ime.nvim.
The switch_key option must match the toggle key configured in your Windows IME settings.
require('smart-ime').setup({
switch_key = 'ctrl+space', -- IME toggle key (must match Windows IME setting)
save_on = { 'InsertLeave' }, -- Events to save IME state and switch to English
restore_on = { 'InsertEnter' }, -- Events to restore saved IME state
normalize_on = { 'FocusGained' }, -- Events to normalize IME state
delay = 100, -- Delay (ms) for deferred normalization
enable_log = true, -- Enable logging via logger.nvim (no-op if not installed)
})| Option | Type | Default | Description |
|---|---|---|---|
switch_key |
string |
'ctrl+space' |
IME toggle key, must match your Windows IME setting |
save_on |
string[] |
{ 'InsertLeave' } |
Autocmd events that trigger save + switch to English |
restore_on |
string[] |
{ 'InsertEnter' } |
Autocmd events that trigger restore saved IME state |
normalize_on |
string[] |
{ 'FocusGained' } |
Autocmd events that trigger IME normalization |
delay |
number |
100 |
Delay in ms before normalization check (deferred) |
enable_log |
boolean |
true |
Enable logging via logger.nvim (no-op if not installed) |
The key combination used to toggle IME. Parsed into Windows virtual key codes
and sent via keybd_event. This must match the toggle key configured in
your Windows IME settings.
Supported key names:
| Key | VK Code |
|---|---|
ctrl |
0x11 |
shift |
0x10 |
alt |
0x12 |
space |
0x20 |
win |
0x5B |
Combine with +:
switch_key = 'ctrl+space' -- Ctrl+Space (default)
switch_key = 'shift' -- Shift alone
switch_key = 'ctrl+shift' -- Ctrl+ShiftYou can also use raw hex VK codes directly:
switch_key = '0x11+0x20' -- Same as ctrl+spaceUse Shift as the IME toggle key:
require('smart-ime').setup({
switch_key = 'shift',
})Disable logging:
require('smart-ime').setup({
enable_log = false,
})Add CmdlineEnter/CmdlineLeave for command-line mode support:
require('smart-ime').setup({
save_on = { 'InsertLeave', 'CmdlineLeave' },
restore_on = { 'InsertEnter', 'CmdlineEnter' },
})-
How does the plugin switch IME?
The plugin simulates your IME toggle key (e.g.
Ctrl+Space) via the Windowskeybd_eventAPI through PowerShell. It does not query the current IME state — instead, it tracks state per buffer manually (defaulting to Chinese on firstInsertLeave). -
Why does
switch_keyneed to match my Windows setting?Since switching is done by simulating a keystroke, the plugin sends whatever key you configured. If this doesn't match your actual Windows IME toggle key, the keystroke will have no effect on the IME.
-
What if I manually change IME outside Neovim?
The tracked state may become out of sync. The
FocusGainednormalization event helps correct this — when Neovim regains focus, IME is normalized based on the current mode. -
Does this work on macOS or Linux?
No. The plugin relies on PowerShell and the Windows
keybd_eventAPI.
Like this plugin? Star the repository on GitHub.
Love this plugin? Follow me on GitHub or Twitter.
If you encounter any bugs or have suggestions, please file an issue in the issue tracker
Licensed under GPL-3.0.