这两天在用vim写c的时候发现一个奇怪的问题
当用vimim 输入完中文回到英文时,我用imap设定的 括号配对无法使用了
仔细研究发现,当使用过 vimim 后,键盘上只有F1-F-12 这几个键的imap还生效,其余
自己设定的imap都被清空
于是查找原因
首先想到的就是imap问题,于是查看不同情况下的imap
在没有调用vimim时 敲:imap 查看得
i <F9> rintf("\n");
i <F3> <Esc>:!gcc % <CR>
i <Plug>VimIM * <SNR>12_ChineseMode()
i <Plug>VimimOneKey * g:vimim_onekey()
i <F2> * <Esc>:w<CR>a
i <F8> <CR><Esc>78i-<Esc>o
i <F4> * <Esc>:ConqueTermVSplit bash<CR>
i <C-F> <C-X><C-F>
i <C-K> <C-X><C-K>
i <C-L> <C-X><C-L>
i <C-N> <C-X><C-N>
i <C-O> <C-X><C-O>
i <C-P> <C-X><C-P>
i <C-X><C-\> * <SNR>12_VimIMSwitch()
i <C-\> <Plug>VimIM
i <C-^> <Plug>VimimOneKey
i ( ()<Esc>i
i ) <C-R>=ClosePair(')')<CR>
i p <F9><Space>
i { {<CR>}<Esc>O
i } <C-R>=ClosePair('}')<CR>
打开vimim,再查看imap ,如下
i <BS> * <SNR>12_vimim_backspace()
i <F9> rintf("\n");
i <F3> <Esc>:!gcc % <CR>
i <Plug>VimIM * <SNR>12_ChineseMode()
i <Plug>VimimOneKey * g:vimim_onekey()
i <F2> * <Esc>:w<CR>a
i <F8> <CR><Esc>78i-<Esc>o
i <F4> * <Esc>:ConqueTermVSplit bash<CR>
i <C-F> <C-X><C-F>
i <C-K> <C-X><C-K>
i <C-L> <C-X><C-L>
i <CR> * <SNR>12_vimim_enter()
i <C-N> <C-X><C-N>
i <C-O> <C-X><C-O>
i <C-P> <C-X><C-P>
i <C-X><C-\> * <SNR>12_VimIMSwitch()
i <C-\> <Plug>VimIM
i <C-^> * <SNR>12_vimim_punctuation_toggle()
i <Space> * <SNR>12_vimim_space()
i ! * <SNR>12_vimim_chinese_punctuation_map("!")
i " * <C-R>=<SNR>12_vimim_get_quote(2)<CR>
i # * <SNR>12_vimim_chinese_punctuation_map("#")
i $ * <SNR>12_vimim_chinese_punctuation_map("$")
i % * <SNR>12_vimim_chinese_punctuation_map("%")
i & * <SNR>12_vimim_chinese_punctuation_map("&")
i ' * <C-R>=<SNR>12_vimim_get_quote(1)<CR>
i ( * <SNR>12_vimim_chinese_punctuation_map("(")
i ) * <SNR>12_vimim_chinese_punctuation_map(")")
i * * <SNR>12_vimim_chinese_punctuation_map("*")
i + * <SNR>12_vimim_chinese_punctuation_map("+")
i , * <SNR>12_vimim_chinese_punctuation_map(",")
i - * <SNR>12_vimim_chinese_punctuation_map("-")
i . * <SNR>12_vimim_chinese_punctuation_map(".")
i 0 * <SNR>12_vimim_alphabet_number_label("0")
i 1 * <SNR>12_vimim_alphabet_number_label("1")
i 2 * <SNR>12_vimim_alphabet_number_label("2")
i 3 * <SNR>12_vimim_alphabet_number_label("3")
i 4 * <SNR>12_vimim_alphabet_number_label("4")
i 5 * <SNR>12_vimim_alphabet_number_label("5")
i 6 * <SNR>12_vimim_alphabet_number_label("6")
i 7 * <SNR>12_vimim_alphabet_number_label("7")
i 8 * <SNR>12_vimim_alphabet_number_label("8")
i 9 * <SNR>12_vimim_alphabet_number_label("9")
i : * <SNR>12_vimim_chinese_punctuation_map(":")
i ; * <SNR>12_vimim_chinese_punctuation_map(";")
i < * <SNR>12_vimim_chinese_punctuation_map("<")
i = * <SNR>12_vimim_chinese_punctuation_map("=")
i > * <SNR>12_vimim_chinese_punctuation_map(">")
i ? * <SNR>12_vimim_chinese_punctuation_map("?")
i @ * <SNR>12_vimim_chinese_punctuation_map("@")
i [ * <SNR>12_vimim_chinese_punctuation_map("[")
i \ * <C-R>=pumvisible() ? "<C-Y>" : ""<CR>、
i ] * <SNR>12_vimim_chinese_punctuation_map("]")
i ^ * <SNR>12_vimim_chinese_punctuation_map("^")
i _ * <SNR>12_vimim_chinese_punctuation_map("_")
i a * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>a<C-R>=g:vimim()<CR>
i b * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>b<C-R>=g:vimim()<CR>
i c * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>c<C-R>=g:vimim()<CR>
i d * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>d<C-R>=g:vimim()<CR>
i e * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>e<C-R>=g:vimim()<CR>
i f * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>f<C-R>=g:vimim()<CR>
i g * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>g<C-R>=g:vimim()<CR>
i ^ * <SNR>12_vimim_chinese_punctuation_map("^")
i _ * <SNR>12_vimim_chinese_punctuation_map("_")
i a * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>a<C-R>=g:vimim()<CR>
i b * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>b<C-R>=g:vimim()<CR>
i c * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>c<C-R>=g:vimim()<CR>
i d * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>d<C-R>=g:vimim()<CR>
i e * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>e<C-R>=g:vimim()<CR>
i f * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>f<C-R>=g:vimim()<CR>
i g * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>g<C-R>=g:vimim()<CR>
i h * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>h<C-R>=g:vimim()<CR>
i i * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>i<C-R>=g:vimim()<CR>
i j * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>j<C-R>=g:vimim()<CR>
i k * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>k<C-R>=g:vimim()<CR>
i l * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>l<C-R>=g:vimim()<CR>
i m * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>m<C-R>=g:vimim()<CR>
i n * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>n<C-R>=g:vimim()<CR>
i o * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>o<C-R>=g:vimim()<CR>
i p * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>p<C-R>=g:vimim()<CR>
i q * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>q<C-R>=g:vimim()<CR>
i r * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>r<C-R>=g:vimim()<CR>
i s * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>s<C-R>=g:vimim()<CR>
i t * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>t<C-R>=g:vimim()<CR>
i u * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>u<C-R>=g:vimim()<CR>
i v * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>v<C-R>=g:vimim()<CR>
i w * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>w<C-R>=g:vimim()<CR>
i x * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>x<C-R>=g:vimim()<CR>
i y * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>y<C-R>=g:vimim()<CR>
i z * <C-R>=g:vimim_wubi_ctrl_e_ctrl_y()<CR>z<C-R>=g:vimim()<CR>
i { * <SNR>12_vimim_chinese_punctuation_map("{")
i } * <SNR>12_vimim_chinese_punctuation_map("}")
i ~ * <SNR>12_vimim_chinese_punctuation_map("~")
在关闭vimim后再查看imap ,发现
i <F9> rintf("\n");
i <F3> <Esc>:!gcc % <CR>
i <Plug>VimIM * <SNR>12_ChineseMode()
i <Plug>VimimOneKey * g:vimim_onekey()
i <F2> * <Esc>:w<CR>a
i <F8> <CR><Esc>78i-<Esc>o
i <F4> * <Esc>:ConqueTermVSplit bash<CR>
i <C-F> <C-X><C-F>
i <C-K> <C-X><C-K>
i <C-L> <C-X><C-L>
i <C-N> <C-X><C-N>
i <C-O> <C-X><C-O>
i <C-P> <C-X><C-P>
i <C-X><C-\> * <SNR>12_VimIMSwitch()
i <C-\> <Plug>VimIM
i <C-^> <Plug>VimimOneKey
通过上面三个的比较,可以明白是怎么回事了,当启用vimim后,vimim 会通过imap 对
按键进行映射,对字母进行调用 匹配的函数, 对标点、符号则把半角换成全角。当
vimim被关闭后,程序调用函数把上面的映射清除,于是原先自己设定的imap就没有了。
于是想通过修改原代码,让它不去改动我需要的一些标点
打开 vimim.vim
首先看到这一段函数,从字面上看它是控制 打开和关闭vimim时执行的动作
function! s:vimim_start()
sil!call s:vimim_plugin_conflict_fix_on()
sil!call s:vimim_i_setting_on()
sil!call s:vimim_super_reset()
sil!call s:vimim_label_on()
sil!call s:vimim_helper_mapping_on()
set noruler
highlight! link Cursor CursorIM
endfunction
function! g:vimim_stop()
sil!call s:vimim_i_setting_off()
sil!call s:vimim_super_reset()
sil!call s:vimim_i_map_off()
sil!call s:vimim_plugin_conflict_fix_off()
sil!call s:vimim_chinesemode_mapping()
sil!call s:vimim_onekey_mapping()
sil!call s:vimim_restore_skin()
endfunction
一直没有找到设定imap的函数在哪,把start中的函数挨个注释都没找到。
但发现stop函数中的s:vimim_i_map_off(),是控制是否清空imap功能的,于是去看该
函数
function! s:vimim_i_map_off()
let recycles = range(0,9) + s:valid_keys
if s:chinese_input_mode !~ 'dynamic' && empty(s:vimim_latex_suite)
let recycles += s:AZ_list
endif
let recycles += keys(s:evils) + keys(s:punctuations)
let recycles += ['<Esc>','<CR>','<BS>','<Space>']
for _ in recycles
if len(maparg(_, 'i')) > 0
sil!exe 'iunmap '. _
endif
endfor
endfunction
从中发现了punctuations ,搜索之,发现要找的东西了
function! s:vimim_dictionary_punctuation()
let s:punctuations = {}
let s:punctuations['@'] = s:space
let s:punctuations[':'] = s:colon
let s:punctuations['['] = s:left
let s:punctuations[']'] = s:right
let s:punctuations['#'] = '#'
let s:punctuations['&'] = '&'
let s:punctuations['%'] = '%'
let s:punctuations['$'] = '¥'
let s:punctuations['!'] = '!'
let s:punctuations['~'] = '~'
let s:punctuations['('] = '('
let s:punctuations[')'] = ')'
let s:punctuations['{'] = '〖'
let s:punctuations['}'] = '〗'
let s:punctuations['^'] = '……'
let s:punctuations['_'] = '——'
let s:punctuations['<'] = '《'
let s:punctuations['>'] = '》'
let s:punctuations['+'] = "+"
let s:punctuations['-'] = '-'
let s:punctuations['='] = '='
let s:punctuations[';'] = ';'
let s:punctuations[','] = ','
let s:punctuations['.'] = '。'
let s:punctuations['?'] = '?'
let s:punctuations['*'] = '�~'
let s:evils = {}
if empty(s:vimim_backslash_close_pinyin)
let s:evils['\'] = '、'
endif
if empty(s:vimim_latex_suite)
let s:evils["'"] = '‘’'
let s:evils['"'] = '“”'
endif
endfunction
这就是那个把标点符号从半角换成全角的函数
于是……把不能让它imap的 注释掉
let s:punctuations = {}
" let s:punctuations['@'] = s:space
" let s:punctuations[':'] = s:colon
" let s:punctuations['['] = s:left
" let s:punctuations[']'] = s:right
" let s:punctuations['#'] = '#'
" let s:punctuations['&'] = '&'
" let s:punctuations['%'] = '%'
" let s:punctuations['$'] = '¥'
" let s:punctuations['!'] = '!'
let s:punctuations['~'] = '~'
" let s:punctuations['('] = '('
" let s:punctuations[')'] = ')'
" let s:punctuations['{'] = '〖'
" let s:punctuations['}'] = '〗'
let s:punctuations['^'] = '……'
let s:punctuations['_'] = '——'
" let s:punctuations['<'] = '《'
" let s:punctuations['>'] = '》'
let s:punctuations['+'] = "+"
let s:punctuations['-'] = '-'
" let s:punctuations['='] = '='
" let s:punctuations[';'] = ';'
let s:punctuations[','] = ','
let s:punctuations['.'] = '。'
" let s:punctuations['?'] = '?'
" let s:punctuations['*'] = '�~'
ok,保存退出,去试试效果 perfect啊
现在写c就更爽了,括号配对,中文输入插件 ,哈哈哈……