From dadbc1a2b1a9a218c218ddb816c88c5478ce9197 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 12 Nov 2018 23:05:40 +0800 Subject: vim: Add plugin fcitx.vim Credit: https://github.com/lilydjwg/fcitx.vim --- _vim/plugin/fcitx.vim | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 _vim/plugin/fcitx.vim (limited to '_vim/plugin') diff --git a/_vim/plugin/fcitx.vim b/_vim/plugin/fcitx.vim new file mode 100644 index 0000000..c0253a1 --- /dev/null +++ b/_vim/plugin/fcitx.vim @@ -0,0 +1,44 @@ +" +" Remember and restore Fcitx's state for each buffer separately when +" leaving/entering insert mode, while always switch Fcitx off in normal +" mode. +" +" Credit: https://github.com/lilydjwg/fcitx.vim +" + +if &compatible || + \ exists("g:fcitx_loaded") || + \ (!exists('$DISPLAY') || exists('$SSH_TTY')) + finish +endif + +if executable('fcitx5-remote') + let g:fcitx_remote = 'fcitx5-remote' +elseif executable('fcitx-remote') + let g:fcitx_remote = 'fcitx-remote' +else + finish +endif + +function Fcitx2en() + if system(g:fcitx_remote) == 2 " Fcitx is active + let b:fcitx_toggle = 1 + call system(g:fcitx_remote . ' -c') " inactivate + endif +endfunction + +function Fcitx2zh() + try + if b:fcitx_toggle == 1 + call system(g:fcitx_remote . ' -o') " activate + let b:fcitx_toggle = 0 + endif + catch /fcitx_toggle/ + let b:fcitx_toggle = 0 + endtry +endfunction + +autocmd InsertLeave * call Fcitx2en() +autocmd InsertEnter * call Fcitx2zh() + +let g:fcitx_loaded = 1 -- cgit v1.2.2