NeoVim 中英文输入法切换的问题 | 您所在的位置:网站首页 › idea切换中文输入法退出 › NeoVim 中英文输入法切换的问题 |
NeoVim 中英文输入法切换的问题
Jun 2, 2023 2023 linux others在使用 Vim/NeoVim 编辑器,特别是由 Insert 切换到 Normal 模式,如果使用到中文输入法,很容易在 Normal 模式下输入中文,就会造成了很多不必要的麻烦。 我们需要的做是在退出 Insert 模式的时候自动切换到英文输入法。 Linux在 Linux 一般都是使用 fcitx 的输入法,关于这个切换,在 Arch Linux Wiki 上关于 Fcitx 的输入法说明也已经给出说明了 autocmd InsertLeave * :silent !fcitx5-remote -c以下是来自官网的用法,本质上都是差不多: let fcitx5state=system("fcitx5-remote") autocmd InsertLeave * :silent let fcitx5state=system("fcitx5-remote")[0] | silent !fcitx5-remote -c autocmd InsertEnter * :silent if fcitx5state == 2 | call system("fcitx5-remote -o") | endif WindowsWindows 在 WSL 里面切换起来是比较麻烦的,主要是借用了系统英文和 im-select.exe 程序。 在 Normal 模式下使用 im-select.exe 切换到系统英文,进入 Insert 模式下使用 im-select.exe 切换到系统中文。 安装英文语言首先是对 Windows 系统进行安装英文系统语言(如已安装则忽略)。 进入 系统设置 -> 时间和语言 -> 语言和区域 -> 添加语言 找到 English(United States) 即 英语(美国),点击下一页进行安装即可。 安装 im-selectGitHub: im-select 页面找到 Windows 的下载链接进行下载。将其放入指定的目录,如:D:\im-select\im-select.exe 在 WSL 可以使用下面的命令进行输入法的切换和操作: /mnt/d/im-select/im-select.exe # 查看当前输入法的代码编号 /mnt/d/im-select/im-select.exe locale # 切换当前输入法 /mnt/d/im-select/im-select.exe 2052 # 切换到中文输入法 /mnt/d/im-select/im-select.exe 1033 # 切换到英文输入法 设置 vimrc在 vimrc 文件中按需设置自动切换的功能 autocmd VimEnter * :silent !(/mnt/d/im-select/im-select.exe 1033) autocmd InsertEnter * :silent !(/mnt/d/im-select/im-select.exe 2052) autocmd InsertLeave * :silent !(/mnt/d/im-select/im-select.exe 1033) autocmd VimLeave * :silent !(/mnt/d/im-select/im-select.exe 2052) VSCodeVim在 VSCode 使用 Vim 插件也需要安装英文语言和 im-select,但没有 vim 下使用更加便捷。 在设置里面设置: "vim.autoSwitchInputMethod.enable": true, "vim.autoSwitchInputMethod.defaultIM": "1033", "vim.autoSwitchInputMethod.obtainIMCmd": "D:\\im-select\\im-select.exe", "vim.autoSwitchInputMethod.switchIMCmd": "D:\\im-select\\im-select.exe {im}", 参考链接 解决 Windows 下(Neo)Vim 中文输入法的切换问题 Arch Wiki: Fcitx5 |
CopyRight 2018-2019 实验室设备网 版权所有 |