fcitx5 和 vim 的配合使用

最近更新了输入法,用上了 fcitx5 输入法,之前的 fcitx 的部分设置需要更新了。但是目前 Arch wiki 还没做出更新,因此在这里做个简单的记录。


vim 里面在进行中文输入,突然想切换进命令模式,还要自己改输入法就太不爽了。因此有人开发了vim-fcitx 插件。在 fcitx 的 Arch wiki) 还给了另一种解决方式,就是自己配置 .vimrc 文件实现。但是只给了 fcitx 的实现,没有给 fcitx5 的实现。但是要实现 fcitx5 的实际上很简单,只需要将里面的 fcitx 全部替换成 fcitx5 即可,替换后如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"##### auto fcitx  ###########
let g:input_toggle = 1
function! Fcitx2en()
let s:input_status = system("fcitx5-remote")
if s:input_status == 2
let g:input_toggle = 1
let l:a = system("fcitx5-remote -c")
endif
endfunction

function! Fcitx2zh()
let s:input_status = system("fcitx5-remote")
if s:input_status != 2 && g:input_toggle == 1
let l:a = system("fcitx5-remote -o")
let g:input_toggle = 0
endif
endfunction

set ttimeoutlen=150
"退出插入模式
autocmd InsertLeave * call Fcitx2en()
"进入插入模式
autocmd InsertEnter * call Fcitx2zh()
"##### auto fcitx end ######

于是就舒服的使用 vim 了。对于 Vscode 里面的 vim 插件的处理类似,根据 官方提示 有处理 fcitx 的代码,我们做一样的替换即可。替换后为

1
2
3
4
"vim.autoSwitchInputMethod.enable": true,
"vim.autoSwitchInputMethod.defaultIM": "1",
"vim.autoSwitchInputMethod.obtainIMCmd": "/usr/bin/fcitx5-remote",
"vim.autoSwitchInputMethod.switchIMCmd": "/usr/bin/fcitx5-remote -t {im}",

遗憾的是,目前该插件仅支持部分 .vimrc 设置,不然还可以有另一种处理方式。也就是把 Vscode 里面的 vim 插件也引入普通 vim 里的处理方式的代码,但是目前还不被支持。

Welcome to my other publishing channels