安装im-select brew tap daipeihust/tap && brew install im-select # 获取安装路径 which im-select vscoed setting 新增 { "vim.autoSwitchInputMethod.switchIMCmd": "/usr/local/bin/im-select {im}", "vim.autoSwitchInputMethod.obtainIMCmd ": "/usr/local/bin/im-select", "vim.autoSwitchInputMethod.defaultIM": "com.apple.keylayout.ABC",
im-select 用于在命令行中切换输入法。不带参数执行程序,能获取当前输入法的 ID:im-select这里需要在英文输入法下执行该命令,获取英文输入法的 ID。 im-select 将输入法 ID 作为参数即可切换输入法。 在中文输入法下将刚刚获取的英文输入法 ID 作为参数,可验证输入法从中文切换到英文:im-select com.apple.keylayout.ABC3.2 配置 init.vim为 init.vim im-select ' . g:last_im_select | endif" 在退出插入模式时切换到英文输入法autocmd InsertLeave * silent ! 若 im-select 未写入 PATH 环境变量,在脚本中改用绝对路径即可。
ESC> <ESC>:set iminsert=2<CR> endif MacOS MacOS 自带 Vim,与 gVim 不同,Vim 则需要借助于 smartim 插件来实现,smartim 依赖 im-select 程序,不过在安装 smartim 时会自动安装 im-select。 修改 smartim 命令模式默认的输入法 我当时这一步做完还不行,因为我的 Mac 英文输入法是 com.apple.keylayout.ABC,手动切换到英文输入法,然后使用 im-select 查看 /im-select com.apple.keylayout.ABC 而 smartim 默认的命令模式输入法是 com.apple.keylayout.US,因此需要在 vimrc 中指定 smartim 解决方法是在 smartim.vim 文件中添加 set timeoutlen=0 ❯ pwd /Users/aaron/.vim/bundle/smartim/plugin ❯ ls im-select