"===================================括弧自動關閉========================
function! My_BracketComplete()
let char = strpart(getline('.'), col('.')-1, 1)
if (char == ")")
return "/<Right>"
else
return ")"
endif
endfunction
autocmd Filetype java,javascript,html imap ( ()<left>
autocmd FileType java,javascript,html inoremap ) <C-R>=My_BracketComplete()<CR>
function! My_MidComplete()
let char = strpart(getline('.'), col('.')-1, 1)
if (char == "]")
return "/<Right>"
else
return "]"
endif
endfunction
autocmd Filetype java,javascript,html imap [ []<left>
autocmd FileType java,javascript,html inoremap ] <C-R>=My_MidComplete()<CR>
autocmd Filetype java,javascript,html,css imap { {<esc>xA<esc>pa}<left><cr><cr><up><tab>
function! My_BraceComplete()
let char = strpart(getline('.'), col('.')-1, 1)
if (char == "}")
return "/<Right>"
else
return "}"
endif
endfunction
function! My_appendSemicolon() "在句末添加分號後 ,游標仍回原位置 imap ; <C-R>=My_appendSemicolon()<CR>
let nowPos=col('.') "游標下標
let endPos=col('$') "行尾下標
let len=endPos-nowPos
let line=getline('.')
if matchend(line,";//s/*$")==strlen(line) " 如果 此行以分號結尾(包括分號後面有空格的情況) 則不將分號加到末尾,而是游標處
return ";"
else
return repeat("/<Right>",len).";".repeat("/<Left>",len+1) "在行尾添加分號並回到原位置
endif
endfunction
"============================end of 括弧自動關閉========================
"與omni結合使用的時候 當提示方法名的時個一般是這種情形 System.out.print(
"而不是System.out.println() 注意最後的括弧,此函數要做的就是當使用提示的時候
"補上右括弧
function! My_BracketComplete4omni()
let line=getline('.') "| example: line= System.ouout
let dotPos=strridx(line,".") "lengthOf(' System.')-1 最後一個點.所在的位置
let cursePos=strlen(line) "lengthOf(' System.ouout') 游標的位置
let len=cursePos-dotPos "lengthof(ouout)+1 游標到最後一個點之間 的長度
let lastCharIndex=strridx(line,'(') "得到最後一個左括弧的下標,判斷是否需要補上一個右括弧
let bedot=strpart(line,0,dotPos) " System 最後一個點之前的部分
let afdot=strpart(line,dotPos+1,len) "ouout 最後一個點之後 的部分
let b=match(afdot,'/(/w/+/)/1') " the begin index of ouou
let e=matchend(afdot,'/(/w/+/)/1') " the end index of ouou
let ok=strpart(afdot,(e-b)/2) " out ,all the char after the first 'u' of ouout
"debug
"return repeat("/<BS>",len-1).ok."/nline:".line."/ndotPos:".dotPos."/ncursePos:".cursePos."/nlen:".len."/nlastCharIndex:".lastCharIndex."/nbedot:".bedot."/nafdot:".afdot."/nb:".b."/ne:".e."/nok:".ok."/nrep:".rep
let rep=repeat("/<Left>",strlen(ok)-1) "向前移動strlen(ok) 個長度的位置,以便刪除ouout 最前面出現的重複的ou
let lenOfOk=strlen(ok)
let lenOfBetweenDotAndOk=len-lenOfOk
let rep=rep.repeat("/<BS>", lenOfBetweenDotAndOk-1) "刪除ouout 最前面出現的重複的ou
let rep=rep.repeat("/<Right>",lenOfOk) "游標向後移動到最初的位置
if lastCharIndex == -1
if dotPos== -1
return " "
else
return rep
endif
else
return rep.")/<Left>"
endif
endfunction
let g:closetag_html_style=1
autocmd FileType xml,html imap > ><C-_>
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd Filetype java set omnifunc=javacomplete#Complete
autocmd Filetype java set completefunc=javacomplete#CompleteParamsInf
autocmd FileType java,javascript,html,css imap ; <C-R>=My_appendSemicolon()<CR><esc>
autocmd FileType java,javascript,html,css map ; i;
autocmd FileType java,javascript,html imap " "<cr><esc>kA<esc>xa<esc>ppJhi
autocmd FileType java,javascript,html,vim imap ' '<cr><esc>kA<esc>xa<esc>ppJi
autocmd Filetype java,javascript inoremap <buffer> . .<C-X><C-O><C-P>
autocmd Filetype css inoremap <buffer> : :<C-X><C-O><C-P>
autocmd Filetype css,javascript,java inoremap <buffer> <tab> <C-O>
autocmd Filetype javascript,css inoremap <buffer> <SPACE> <C-X><C-O><C-P><C-R>=My_BracketComplete4omni()<CR>
autocmd Filetype java,javascript,css,html, inoremap <buffer> <F2> <C-O><C-X><C-O><C-P><C-R>=My_BracketComplete4omni()<CR>
autocmd Filetype java,javascript,css,html inoremap <buffer> <F3> <C-O><C-X><C-O><C-P><C-R>=My_BracketComplete4omni()<CR>
autocmd Filetype java,javascript,css,html inoremap <buffer> <F1> <C-O><C-X><C-O><C-P><C-R>=My_BracketComplete4omni()<CR>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> a a<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> b b<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> c c<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> d d<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> e e<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> f f<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> g g<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> h h<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> i i<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> j j<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> k k<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> l l<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> m m<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> n n<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> o o<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> p p<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> q q<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> r r<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> s s<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> t t<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> u u<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> v v<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> w w<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> x x<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> y y<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> z z<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> A A<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> B B<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> C C<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> D D<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> E E<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> F F<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> G G<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> H H<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> I I<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> J J<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> K K<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> L L<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> M M<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> N N<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> O O<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> P P<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> Q Q<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> R R<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> S S<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> T T<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> U U<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> V V<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> W W<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> X X<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> Y Y<C-N><C-P>
autocmd Filetype java,javascript,css,html,xml inoremap <buffer> Z Z<C-N><C-P>