fcitx提供了一个基于socket的工具,fcitx-remote可以用于控制fcitx
具体命令参数参见fcitx-remote -h 和 man
一个实用的例子是用它自动控制vim的输入状态
let g:input_toggle = 1
function! Fcitx2en()
let s:input_status = system("fcitx-remote")
if s:input_status == 2
let g:input_toggle = 1
let l:a = system("fcitx-remote -c")
endif
endfunction
function! Fcitx2zh()
let s:input_status = system("fcitx-remote")
if s:input_status != 2 && g:input_toggle == 1
let l:a = system("fcitx-remote -o")
let g:input_toggle = 0
endif
endfunction
set timeoutlen=150
autocmd InsertLeave * call Fcitx2en()
"autocmd InsertEnter * call Fcitx2zh()
将上面的代码加入 ~/.vimrc 中,可以实现退出插入模式时自动关闭输入法。去掉最后一行的注释可以实现进入插入模式自动启用输入法。