├── README.md └── plugin └── fcitx-osx.vim /README.md: -------------------------------------------------------------------------------- 1 | # fcitx-vim-osx 2 | Modified fcitx.vim for osx with https://github.com/CodeFalling/fcitx-remote-for-osx 3 | 4 | lazy load this plugin. it will reduce 70ms at vim startup. 5 | ``` 6 | Plugin 'CodeFalling/fcitx-vim-osx' 7 | ``` 8 | 9 | # For OS X 10 | 11 | You have to install https://github.com/CodeFalling/fcitx-remote-for-osx 12 | 13 | # Thanks 14 | 15 | This project is just a modified version of https://github.com/vim-scripts/fcitx.vim developed by [lilydjwg](https://github.com/lilydjwg) 16 | -------------------------------------------------------------------------------- /plugin/fcitx-osx.vim: -------------------------------------------------------------------------------- 1 | " fcitx.vim 记住插入模式小企鹅输入法的状态 2 | " Author: lilydjwg 3 | " Maintainer: lilydjwg 4 | " Modified by: codefalling 5 | " Note: 另有使用 Python3 接口的新版本 6 | " 此修改版用于 OS X 下的 https://github.com/CodeFalling/fcitx-remote-for-osx 7 | " --------------------------------------------------------------------- 8 | " Load Once: 9 | if exists('g:fcitx_remote') 10 | finish 11 | endif 12 | 13 | if &ttimeoutlen <= 0 || &ttimeoutlen > 50 14 | set ttimeoutlen=50 15 | endif 16 | 17 | if (has("win32") || has("win95") || has("win64") || has("win16")) 18 | " Windows 下不要载入 19 | finish 20 | endif 21 | if exists('$SSH_TTY') 22 | finish 23 | endif 24 | if !executable("fcitx-remote") 25 | finish 26 | endif 27 | let s:keepcpo = &cpo 28 | let g:loaded_fcitx = 1 29 | set cpo&vim 30 | " --------------------------------------------------------------------- 31 | " Functions: 32 | function Fcitx2en() 33 | let inputstatus = system("fcitx-remote") 34 | if inputstatus == 2 35 | let b:inputtoggle = 1 36 | let t = system("fcitx-remote -c") 37 | endif 38 | endfunction 39 | function Fcitx2zh() 40 | try 41 | if b:inputtoggle == 1 42 | let t = system("fcitx-remote -o") 43 | let b:inputtoggle = 0 44 | endif 45 | catch /inputtoggle/ 46 | let b:inputtoggle = 0 47 | endtry 48 | endfunction 49 | " --------------------------------------------------------------------- 50 | " Autocmds: 51 | function Fcitx2zhOnce() 52 | call Fcitx2zh() 53 | call UnBindAu() 54 | endfunction 55 | 56 | function BindAu2zhOnce() 57 | augroup Fcitx 58 | au InsertEnter * call Fcitx2zhOnce() 59 | augroup END 60 | endfunction 61 | 62 | function BindAu() 63 | augroup Fcitx 64 | au InsertLeave * call Fcitx2en() 65 | au InsertEnter * call Fcitx2zh() 66 | au VimEnter * call Fcitx2en() 67 | augroup END 68 | endfunction 69 | 70 | function UnBindAu() 71 | au! Fcitx InsertLeave * 72 | au! Fcitx InsertEnter * 73 | endfunction 74 | 75 | "call once when enter insert mode instead of vim startup 76 | let g:called_bind = 0 77 | function EchoBind() 78 | if (g:called_bind==0) 79 | call BindAu() 80 | endif 81 | let g:called_bind =1 82 | endfunction 83 | 84 | autocmd InsertEnter * call EchoBind() 85 | 86 | "Called once right before you start selecting multiple cursors 87 | function! Multiple_cursors_before() 88 | call UnBindAu() 89 | call BindAu2zhOnce() 90 | endfunction 91 | 92 | function! Multiple_cursors_after() 93 | call Fcitx2en() 94 | call BindAu() 95 | endfunction 96 | 97 | " --------------------------------------------------------------------- 98 | " Restoration And Modelines: 99 | let &cpo=s:keepcpo 100 | unlet s:keepcpo 101 | "vim:fdm=expr:fde=getline(v\:lnum-1)=~'\\v"\\s*-{20,}'?'>1'\:1 102 | 103 | let g:fcitx_remote = 1 104 | --------------------------------------------------------------------------------