qtcreator fakevim 自动切换中英输入法

很久以前写过一篇文章介绍如何在 linux 下的 qtcreator 自动切换输入法,当时使用的方法比较简陋,而且只支持 linux,时过境迁,虽然 qtcreator 的 fakevim 插件功能仍然有限,但我搞出来了个跨平台的自动切换方案。

qtcreator fakevim 的配置文件中增加如下内容:

1
2
3
4
5
6
7
8
9
10
" 自动切换输入法
" 需要将可执行脚本文件放到标准可执行目录下,如:/usr/local/bin/
inoremap <ESC> <ESC>:!fakevim-smartim en<CR>
nnoremap i :!fakevim-smartim re<CR>i
nnoremap I :!fakevim-smartim re<CR>I
nnoremap a :!fakevim-smartim re<CR>a
nnoremap A :!fakevim-smartim re<CR>A
nnoremap s :!fakevim-smartim re<CR>s
nnoremap S :!fakevim-smartim re<CR>S

上述配置映射了些按键,在切换输入模式前,调用可执行程序 fakevim-smartim,这是我使用 golang 编写的一个小工具,源码:https://github.com/listenerri/scripts/tree/master/bin-srcs/fakevim-smartim

有编译好的二进制可以直接下载:

将下载或自己编译好的二进制重命名为 fakevim-smartim 并放到系统的可执行程序目录下,也就是 PATH 环境变量中的任意目录。

其他依赖:

  • linux 仅支持小企鹅输入法 fcitx,且依赖可执行程序 fcitx5-remote,这是较新版本的 fcitx 包中带有的命令,如果你使用的是旧版本的 fcitx,那么对应的应该是 fcitx-remote,可以修改 fakevim-smartim 的源码,将调用命令修改为 fcitx-remote,或者直接在 fcitx-remote 命令所在位置,创建一个符号链接 ln -sf fcitx-remote fcitx5-remote(未测试)。
  • windows 依赖另一个小工具:im-select,下载地址: https://github.com/daipeihust/im-select/tree/master/win/out
  • macos 同样依赖 im-select,下载地址: https://github.com/daipeihust/im-select/tree/master/macOS/out