Skip to content

Instantly share code, notes, and snippets.

@haruue
Created December 2, 2017 03:36
Show Gist options
  • Save haruue/6e21b5ecea6fb4f9af640c86e3195306 to your computer and use it in GitHub Desktop.
Save haruue/6e21b5ecea6fb4f9af640c86e3195306 to your computer and use it in GitHub Desktop.
ibus.vim
" ibus.vim 记住插入模式小企鹅输入法的状态
" Author: lilydjwg/vim-fcitx
" Maintainer: haruue
" ---------------------------------------------------------------------
" Load Once:
if (has("win32") || has("win95") || has("win64") || has("win16"))
" Windows 下不要载入
finish
endif
if !exists('$DISPLAY') || exists('$SSH_TTY') || has('gui_macvim')
finish
endif
if &cp || exists("g:loaded_ibus") || !executable("ibus")
finish
endif
let s:keepcpo = &cpo
let g:loaded_ibus = 1
set cpo&vim
" ---------------------------------------------------------------------
" Functions:
function Ibus2en()
let b:inputstatus = system("ibus engine")
if b:inputstatus != "xkb:us::eng"
let b:inputtoggle = 1
call system("ibus engine 'xkb:us::eng'")
endif
endfunction
function Ibus2zh()
try
if b:inputtoggle == 1
call system("ibus engine " . b:inputstatus)
let b:inputtoggle = 0
endif
catch /inputtoggle/
let b:inputtoggle = 0
endtry
endfunction
" ---------------------------------------------------------------------
" Autocmds:
au InsertLeave * call Ibus2en()
au InsertEnter * call Ibus2zh()
" ---------------------------------------------------------------------
" Restoration And Modelines:
let &cpo=s:keepcpo
unlet s:keepcpo
" vim:fdm=expr:fde=getline(v\:lnum-1)=~'\\v"\\s*-{20,}'?'>1'\:1
@haruue
Copy link
Author

haruue commented Dec 2, 2017

之前用 ibus 的时候改的,由于不再使用 ibus 所以备份到这里。
https://github.com/vim-scripts/fcitx.vim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment