A command line utility for Windows that helps you switch keyboard layouts, especially designed for vim users.
Lists all installed keyboard layouts with their index, KLID (Keyboard Layout ID), layout name and active status.
Shows the currently active keyboard layout.
Activates the keyboard layout specified by KLID.
Index KLID Layout Name Status
----- ---- ----------- ------
1 00000409 US
2 00060409 Colemak
3 00000411 Japanese
4 00000804 Chinese (Simplified) - US *Active*
Examples:
kbswitch --activate 00000409: Activate the US keyboardkbswitch --activate 00060409: Activate the Colemak keyboardkbswitch --activate 00000411: Activate the Japanese keyboardkbswitch --activate 00000804: Activate the Chinese (Simplified) keyboard
Saves the current keyboard layout to a temporary file for later restoration.
Restores the previously cached keyboard layout.
Shows the current version of kbswitch.
- Make sure
kbswitch.exeis in yourPATH. - Add the following lines to your
init.lua:
local kb_switch_group = vim.api.nvim_create_augroup("KBSwitch", { clear = true })
vim.api.nvim_create_autocmd("InsertLeave", {
pattern = "*",
group = kb_switch_group,
callback = function()
vim.fn.jobstart("kbswitch --cache && kbswitch --activate 00000409") -- Replace with your preferred layout KLID
end
})
vim.api.nvim_create_autocmd("InsertEnter", {
pattern = "*",
group = kb_switch_group,
callback = function()
vim.fn.jobstart("kbswitch --restore")
end
})Note: This setup allows Neovim to automatically:
- Cache your current keyboard layout and switch to a specified layout when leaving insert mode
- Restore your previous layout when entering insert mode
- This program requires read access to the Windows registry to query keyboard layouts.
- This program writes to the
%TEMP%directory to store cached keyboard layout information.
Compatible with modern Windows systems (Windows 8+). Tested on Windows 11 64-bit.
MIT