针对我认为原有脚本补全的不足,我主要做了一下几个方面的补充:
1)定义了<S-ENTER>快捷键,用于跳出括号,省去了再按ESC,然后移动。但有一个不足,就是,对于多重大括号,是跳到最后一个的下一行。没想到什么更好的办法,希望能有人给改改;
2)定义了<S-SPACE>快捷键,用于跳过括号,相当与normal状态下的l;
3)定义了“;;”快捷键,主要是方便的在多重括号中直接移动到行尾,并添加“;”;
4)对大括号的(“{}”)的补全做了判断,分几种情况处理,以保证格式。
代码: 全选
:inoremap <S-ENTER> <c-r>=SkipPair()<CR>
:inoremap <S-SPACE> <ESC>la
:inoremap <C-ENTER> <ESC>A;<CR>
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { <c-r>=ClsoeBrace()<CR>
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap ;; <ESC>A;<CR>
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function Semicolon()
"echo getline('.')[col('.')]
if getline('.')[col('.')] == ')'
return "<ESC>A;"
elseif getline('.')[col('.')] == '}'
return "\<ESC>A;"
elseif getline('.')[col('.')] == ']'
return "\<ESC>A;"
else
return ";"
endif
endf
function SkipPair()
if getline('.')[col('.') - 1] == ')'
return "\<ESC>o"
else
normal j
let curline = line('.')
let nxtline = curline
while curline == nxtline
if getline('.')[col('.') - 1] == '}'
normal j
let nxtline = nxtline + 1
let curline = line('.')
continue
else
return "\<ESC>i"
endif
endwhile
return "\<ESC>o"
endif
endf
function ClsoeBrace()
if getline('.')[col('.') - 2] == '='
return "{}\<ESC>i"
elseif getline('.')[col('.') - 3] == '='
return "{}\<ESC>i"
elseif getline('.')[col('.') - 1] == '{'
return "{}\<ESC>i"
elseif getline('.')[col('.') - 2] == '{'
return "{}\<ESC>i"
elseif getline('.')[col('.') - 2] == ','
return "{}\<ESC>i"
elseif getline('.')[col('.') - 3] == ','
return "{}\<ESC>i"
else
return "{\<ENTER>}\<ESC>O"
endif
endf