这两天在用vim写c的时候发现一个奇怪的问题
当用vimim 输入完中文回到英文时,我用imap设定的 括号配对无法使用了
仔细研究发现,当使用过 vimim 后,键盘上只有F1-F-12 这几个键的imap还生效,其余
自己设定的imap都被清空
于是查找原因
首先想到的就是imap问题,于是查看不同情况下的imap
在没有调用vimim时 敲:imap 查看得
i rintf("\n");
i :!gcc %
i VimIM * 12_ChineseMode()
i VimimOneKey * g:vimim_onekey()
i * :wa
i 78i-o
i * :ConqueTermVSplit bash
i
i
i
i
i
i
i * 12_VimIMSwitch()
i VimIM
i VimimOneKey
i ( ()i
i ) =ClosePair(')')
i p
i { {}O
i } =ClosePair('}')
打开vimim,再查看imap ,如下
i * 12_vimim_backspace()
i rintf("\n");
i :!gcc %
i VimIM * 12_ChineseMode()
i VimimOneKey * g:vimim_onekey()
i * :wa
i 78i-o
i * :ConqueTermVSplit bash
i
i
i
i * 12_vimim_enter()
i
i
i
i * 12_VimIMSwitch()
i VimIM
i * 12_vimim_punctuation_toggle()
i * 12_vimim_space()
i ! * 12_vimim_chinese_punctuation_map("!")
i " * =12_vimim_get_quote(2)
i # * 12_vimim_chinese_punctuation_map("#")
i $ * 12_vimim_chinese_punctuation_map("$")
i % * 12_vimim_chinese_punctuation_map("%")
i & * 12_vimim_chinese_punctuation_map("&")
i ' * =12_vimim_get_quote(1)
i ( * 12_vimim_chinese_punctuation_map("(")
i ) * 12_vimim_chinese_punctuation_map(")")
i * * 12_vimim_chinese_punctuation_map("*")
i + * 12_vimim_chinese_punctuation_map("+")
i , * 12_vimim_chinese_punctuation_map(",")
i - * 12_vimim_chinese_punctuation_map("-")
i . * 12_vimim_chinese_punctuation_map(".")
i 0 * 12_vimim_alphabet_number_label("0")
i 1 * 12_vimim_alphabet_number_label("1")
i 2 * 12_vimim_alphabet_number_label("2")
i 3 * 12_vimim_alphabet_number_label("3")
i 4 * 12_vimim_alphabet_number_label("4")
i 5 * 12_vimim_alphabet_number_label("5")
i 6 * 12_vimim_alphabet_number_label("6")
i 7 * 12_vimim_alphabet_number_label("7")
i 8 * 12_vimim_alphabet_number_label("8")
i 9 * 12_vimim_alphabet_number_label("9")
i : * 12_vimim_chinese_punctuation_map(":")
i ; * 12_vimim_chinese_punctuation_map(";")
i 12_vimim_chinese_punctuation_map("
i = * 12_vimim_chinese_punctuation_map("=")
i > * 12_vimim_chinese_punctuation_map(">")
i ? * 12_vimim_chinese_punctuation_map("?")
i @ * 12_vimim_chinese_punctuation_map("@")
i [ * 12_vimim_chinese_punctuation_map("[")
i \ * =pumvisible() ? "" : ""、
i ] * 12_vimim_chinese_punctuation_map("]")
i ^ * 12_vimim_chinese_punctuation_map("^")
i _ * 12_vimim_chinese_punctuation_map("_")
i a * =g:vimim_wubi_ctrl_e_ctrl_y()a=g:vimim()
i b * =g:vimim_wubi_ctrl_e_ctrl_y()b=g:vimim()
i c * =g:vimim_wubi_ctrl_e_ctrl_y()c=g:vimim()
i d * =g:vimim_wubi_ctrl_e_ctrl_y()d=g:vimim()
i e * =g:vimim_wubi_ctrl_e_ctrl_y()e=g:vimim()
i f * =g:vimim_wubi_ctrl_e_ctrl_y()f=g:vimim()
i g * =g:vimim_wubi_ctrl_e_ctrl_y()g=g:vimim()
i ^ * 12_vimim_chinese_punctuation_map("^")
i _ * 12_vimim_chinese_punctuation_map("_")
i a * =g:vimim_wubi_ctrl_e_ctrl_y()a=g:vimim()
i b * =g:vimim_wubi_ctrl_e_ctrl_y()b=g:vimim()
i c * =g:vimim_wubi_ctrl_e_ctrl_y()c=g:vimim()
i d * =g:vimim_wubi_ctrl_e_ctrl_y()d=g:vimim()
i e * =g:vimim_wubi_ctrl_e_ctrl_y()e=g:vimim()
i f * =g:vimim_wubi_ctrl_e_ctrl_y()f=g:vimim()
i g * =g:vimim_wubi_ctrl_e_ctrl_y()g=g:vimim()
i h * =g:vimim_wubi_ctrl_e_ctrl_y()h=g:vimim()
i i * =g:vimim_wubi_ctrl_e_ctrl_y()i=g:vimim()
i j * =g:vimim_wubi_ctrl_e_ctrl_y()j=g:vimim()
i k * =g:vimim_wubi_ctrl_e_ctrl_y()k=g:vimim()
i l * =g:vimim_wubi_ctrl_e_ctrl_y()l=g:vimim()
i m * =g:vimim_wubi_ctrl_e_ctrl_y()m=g:vimim()
i n * =g:vimim_wubi_ctrl_e_ctrl_y()n=g:vimim()
i o * =g:vimim_wubi_ctrl_e_ctrl_y()o=g:vimim()
i p * =g:vimim_wubi_ctrl_e_ctrl_y()p=g:vimim()
i q * =g:vimim_wubi_ctrl_e_ctrl_y()q=g:vimim()
i r * =g:vimim_wubi_ctrl_e_ctrl_y()r=g:vimim()
i s * =g:vimim_wubi_ctrl_e_ctrl_y()s=g:vimim()
i t * =g:vimim_wubi_ctrl_e_ctrl_y()t=g:vimim()
i u * =g:vimim_wubi_ctrl_e_ctrl_y()u=g:vimim()
i v * =g:vimim_wubi_ctrl_e_ctrl_y()v=g:vimim()
i w * =g:vimim_wubi_ctrl_e_ctrl_y()w=g:vimim()
i x * =g:vimim_wubi_ctrl_e_ctrl_y()x=g:vimim()
i y * =g:vimim_wubi_ctrl_e_ctrl_y()y=g:vimim()
i z * =g:vimim_wubi_ctrl_e_ctrl_y()z=g:vimim()
i { * 12_vimim_chinese_punctuation_map("{")
i } * 12_vimim_chinese_punctuation_map("}")
i ~ * 12_vimim_chinese_punctuation_map("~")
在关闭vimim后再查看imap ,发现
i rintf("\n");
i :!gcc %
i VimIM * 12_ChineseMode()
i VimimOneKey * g:vimim_onekey()
i * :wa
i 78i-o
i * :ConqueTermVSplit bash
i
i
i
i
i
i
i * 12_VimIMSwitch()
i VimIM
i 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 += ['','','','']
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就更爽了,括号配对,中文输入插件 ,哈哈哈……