eis/config/bash/vimrc

102 lines
2.4 KiB
VimL

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
behave xterm
"set fileencodings=utf-8,gb2312
"set fileencodings=utf-8
set fileencodings=utf-8,gb2312
set tabstop=2
set shiftwidth=2
set nocp
set mouse=""
set paste
set smartindent
filetype plugin on
set diffexpr=MyDiff()
set tags=tags;/
set nobackup
nmap <C-C> <Esc>:Setcomment<CR>
imap <C-C> <Esc>:Setcomment<CR>
vmap <C-C> <Esc>:SetcommentV<CR>
command! -nargs=0 Setcomment call s:SET_COMMENT()
command! -nargs=0 SetcommentV call s:SET_COMMENTV()
function! s:SET_COMMENT()
let lindex=line(".")
let str=getline(lindex)
let CommentMsg=s:IsComment(str)
call s:SET_COMMENTV_LINE(lindex,CommentMsg[1],CommentMsg[0])
endfunction
function! s:SET_COMMENTV()
let lbeginindex=line("'<")
let lendindex=line("'>")
let str=getline(lbeginindex)
let CommentMsg=s:IsComment(str)
let i=lbeginindex
while i<=lendindex
call s:SET_COMMENTV_LINE(i,CommentMsg[1],CommentMsg[0])
let i=i+1
endwhile
endfunction
function! s:SET_COMMENTV_LINE( index,pos, comment_flag )
let poscur = [0, 0,0, 0]
let poscur[1]=a:index
let poscur[2]=a:pos+1
call setpos(".",poscur)
if a:comment_flag==0
exec "normal! 0"
exec "normal! i//"
else
exec "normal! xx"
endif
endfunction
function! s:IsComment(str)
let ret= [0, 0]
let i=0
let strlen=len(a:str)
while i<strlen
if !(a:str[i]==' ' || a:str[i] == ' ' )
let ret[1]=i
if a:str[i]=='/' && a:str[i+1]=='/'
let ret[0]=1
else
let ret[0]=0
endif
return ret
endif
let i=i+1
endwhile
return [0,0]
endfunction
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
colorscheme evening