aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-11-12 23:05:40 +0800
committerAaron LI <aly@aaronly.me>2018-11-12 23:05:40 +0800
commitdadbc1a2b1a9a218c218ddb816c88c5478ce9197 (patch)
tree032a113dcb482ca41ace47c0bc53e08037e5ad0a
parent69e4261cb33c74b81cbfc2d7320c8c276cf7cb8d (diff)
downloaddotfiles-dadbc1a2b1a9a218c218ddb816c88c5478ce9197.tar.bz2
vim: Add plugin fcitx.vim
Credit: https://github.com/lilydjwg/fcitx.vim
-rw-r--r--_vim/plugin/fcitx.vim44
1 files changed, 44 insertions, 0 deletions
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