Linux下vim配置文件(无第三方插件版本)

vim_settings_without_plugins

"==============================================================
"    Copyright (c) 2015 Abodu.com Inc. All Rights Reserved
"
" FNAME: vimrc_without_plugins
" Brief: vim settings
" Authr: jealdean
" VERNO: 1.0.2.16
" CHGON: 2015-05-14 20:18:26
" Lastest_Update_At:[ http://www.github.com/jealdean/abodu ]
"==============================================================
"GLOBAL-VARIABLES
let g:mapleader=‘;‘
let g:GV_AUTHOR=‘RollStone‘
let g:GV_EMAIL=‘[email protected]‘
let g:GV_COMPANY=‘ All Rights Reserved By www.abodu.com ‘

"GENERAL_SETTINGS:{{{1
"Basic: {{{2
set nu noet bs=2 sts=4 ts=4 sw=4 tw=80
set nobk noeb wrap lbr hidden
set is nohls sc sm acd ttm=100
set nolist listchars=tab:\|\ 
set ai si ww=h,l,>,<
"when usetabauto-complete will skip files with these suffixes
set wig=*.bak,*.o,*.e,*~,*.sw*
set errorformat=%f:%l:%m cot=longest,menu
"Colors:{{{2
set t_Co=256
"let g:solarized_termcolors=256
colo default
" Encodings:{{{2
set encoding=utf-8
set fenc=utf-8
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936,chinese
"Folds:{{{2
set fen fdc=2 fdl=0 fdm=marker
nnoremap <space> @=((foldclosed(line(‘.‘))<0)?‘zc‘:‘zo‘)<cr>
"Status_line:{{{2
"always show status line
set ls=2 stl=%F[%1*%M%*%n%R%H%w%m%h][%l,%v,%p%%]\ %=
set stl+=\ %0([%{&ft},%{&fileformat},%{&fileencoding}][%{strftime(‘%Y%m%d-%H:%M:%S‘)}]%)

"FUNCTIONS:{{{1
"global variables for funcs
let g:DectectFloor=10
let g:VernoFloor=100
"HCF:HeaderCommentFlag
let g:HCF_PROGRAMS="^/.*$"  "‘//‘ or ‘/*‘,just check the first <s:DectectFloor> lines
let g:HCF_SCRIPTS="^#!/.*$" "just check the first line
let g:HCF_VIMS="^\".*$"      " ‘\"‘,just check the first <s:DectectFloor> lines
let g:HCI_AUTHR=‘AUTHRlet g:HCI_BRIEF=‘BRIEFlet g:HCI_CHGON=‘CHGONlet g:HCI_CREAT=‘CREATlet g:HCI_EMAIL=‘EMAILlet g:HCI_FNAME=‘FNAMElet g:HCI_VERNO=‘VERNO"UD_Add: {{{2 
func! UD_Add()
    let n = 1
    "Check:HeaderCommentFlag exist 
    while n < g:DectectFloor
        let line = getline(n)
        if ( n==1 && line =~ g:HCF_SCRIPTS )
            return 
        endif
        if ( line =~ g:HCF_PROGRAMS || line =~ g:HCF_VIMS)
            return 
        endif
        let n+=1
    endwhile

    "Dectect: GuardLineAndFic
    let lGLS=‘/*‘
    let lGLE=‘ */‘
    let lPF =‘ *!‘
    let lfn=buffer_name(‘%‘)
    if lfn=~ ‘\.sh$‘
        let lGLE=‘‘
        let lPF =‘#‘
        let lGLS=‘#!/bin/sh‘
    elseif lfn =~ ‘\.pl$‘
        let lGLE=‘‘
        let lPF =‘#‘
        let lGLS=‘#!/bin/perl‘
    endif

    "make some local variables
    let lGL=lPF.‘==============================================================‘
    let lCP=lPF.Copyright (c) ‘.strftime(‘%Y‘).‘ ‘.g:GV_COMPANY
    let lPF=lPF.‘ ‘
    let lAuthor =lPF.g:HCI_AUTHR.‘: ‘.g:GV_AUTHOR
    let lDesc   =lPF.g:HCI_BRIEF.‘: ‘
    let lEmail  =lPF.g:HCI_EMAIL.‘: ‘.g:GV_EMAIL
    let lLuTime =lPF.g:HCI_CHGON.‘: ‘.strftime(‘%Y-%m-%d %T‘)
    let lCrTime =lPF.g:HCI_CREAT.‘: ‘.strftime(‘%Y-%m-%d %T‘)
    let lName   =lPF.g:HCI_FNAME.‘: ‘.expand(‘%:t‘)
    let lVersion=lPF.g:HCI_VERNO.‘: 1.0.0.0‘
    call append(0,[lGLS,lGL,lName,lDesc,lAuthor,lEmail,lVersion
                \,lCrTime,lLuTime,lPF,lCP,lGL,lGLE])
endfunc

" UD_CommentToggle: {{{2
func! UD_CommentToggle() range
    let lfn=buffer_name(‘%‘)
    let save_cursor=getpos(‘.‘)

    let patSPACES=‘\(\s\+\)\?‘
    let patSOMECHARS=‘\(.*\)‘
    ".{html,xml,htm,xhtml} 
    if ( lfn =~? ‘\.html$‘ || lfn =~? ‘\.xml$‘ || lfn =~ ‘\.htm‘ || lfn =~ ‘\.xhtml$‘ )  
        let CCB=‘<!--let CCE=‘ -->‘
        let curLine=getline(‘.‘)

        if (curLine =~ CCB..*$‘ && curLine =~ CCE..*$‘ )
            "remove
            execute a:firstline.‘,‘.a:lastline.‘s;‘.CCB.‘;;‘
            execute a:firstline.‘,‘.a:lastline.‘s;‘.CCE.‘;;‘
        else   "add comments
            execute a:firstline.‘,‘.a:lastline.s;^‘.patSPACES.‘\(.*\)‘.patSPACES.‘$;‘.CCB.‘\2‘.CCE.‘;‘
        endif
        exe "silent!: normal :nohls\<cr>"
        return 
    endif

    "OtherFiles_CommonHandler
    let CommentChar=‘#‘    "for perl,shell,makefile and other unknown files

    if ( lfn =~? ‘\.c$‘ || lfn =~? ‘\.h$‘ || lfn =~ ‘\.cpp‘              
        \|| lfn =~ ‘\.hpp$‘ || lfn =~ ‘\.cc‘|| lfn =~ ‘\.java$‘|| lfn =~ ‘\.go$‘ )  "\.{c,cpp,h,hpp,cc,java,C,go}   
        let CommentChar=‘//‘
    elseif ( lfn =~? ‘\.sql$‘)  ".sql  
        let CommentChar=‘--elseif ( lfn =~ ‘\.vim$‘ || lfn =~ ‘\.vimrc$‘ )  "\.{vim,vimrc} 
        let CommentChar=‘"endif

    "the first line is very important ,for:
    "the following lines do the same action with the firstline 
    if getline(a:firstline) =~ ‘^‘.patSPACES.CommentChar..*$‘
        exe "silent :".a:firstline.‘,‘.a:lastline.s;^‘.patSPACES.CommentChar.patSOMECHARS.‘;\1\2;‘
    else
        exe "silent :".a:firstline.‘,‘.a:lastline.s;^;‘.CommentChar . ‘;‘
    endif

    call setpos(‘.‘, save_cursor)
    exe "silent!: normal :nohls\<cr>"
endfunc  "UD_CommentToggle

inoremap  <silent> <C-C> <esc>:call UD_CommentToggle()<CR>:nohls<CR>
noremap  <silent> <C-C> :call UD_CommentToggle()<CR>:nohls<CR>
vnoremap <silent> <C-C> :call UD_CommentToggle()<CR>:nohls<CR>

"end of UD_CommentToggle}}}
"UD_UpdateInfo:{{{2
func! UD_UpdateInfo()
    let n=1
    let updated=0
    while n<g:DectectFloor
        let acl=getline(n)
        "for filename changes
        if (acl =~? ‘name‘ || acl =~? g:HCI_FNAME || acl =~? ‘filename‘|| acl =~? ‘title‘)
            let nacl=substitute(acl,‘:.*$‘,‘: ‘.expand(‘%:t‘),‘g‘)
            call setline(n,nacl)
            let updated = 1
        "for last change time 
        elseif (acl =~? ‘lutime‘ || acl =~? g:HCI_CHGON || acl =~? ‘lastchangeat‘)
            let nacl=substitute(acl,‘:.*$‘,‘: ‘.strftime(‘%Y-%m-%d %T‘),‘g‘)
            call setline(n,nacl)
            let updated = 2
        "for version automatic increase  a little number
        elseif (acl =~? ‘version‘ || acl =~? g:HCI_VERNO || acl =~? ‘revision‘)
            let theLastDotPos=strridx(acl,‘.‘)+1
            "get minmum version number and increase it by 1
            let minVerNo=str2nr(strpart(acl,theLastDotPos))+1 

            if minVerNo >= g:VernoFloor   "if needs a secondMinVerNo increase
                let tempLine=strpart(acl,0,theLastDotPos-1)
                let secondLastDotPos=strridx(tempLine,‘.‘)+1
                let secondMinVerNo=str2nr(strpart(tempLine,secondLastDotPos))+1
                if secondMinVerNo >= g:VernoFloor
                    let secTmpLine=strpart(acl,0,secondLastDotPos-1)
                    let thirdLastDotPos=strridx(secTmpLine,‘.‘)+1
                    let thirdMinVerNo=str2nr(strpart(secTmpLine,thirdLastDotPos))+1
                    let newLine=strpart(acl,0,thirdLastDotPos).thirdMinVerNo.‘.0.0‘
                else
                    let newLine=strpart(acl,0,secondLastDotPos).secondMinVerNo.‘.0‘
                endif
            else
                let newLine=strpart(acl,0,theLastDotPos).minVerNo
            endif
            call setline(n,newLine)
            let updated = 3
        endif
        let n+=1
    endwhile
    if updated == 0
        call UD_Add()
    endif
endfunc

"MAPPINGS:{{{1
"AutoCommand
if has("autocmd")
    au BufReadPost * if line("‘\"") > 0 && line("‘\"") <= line("$") | exe "normal! g`\"" | endif
    au BufEnter * :lch %:p:h
    au InsertEnter * set cul "cuc
    au InsertLeave * set nocuc "nocul
    au BufRead,BufNewFile {make,Make,*mk}* set ft=make noet
    au BufNewFile,BufNew *.{sh,awk,pl,java,c,cc,cpp,C,h,hpp} silent call UD_Add()
    au BufWritePre,FileWritePre,FileAppendPre *.{sh,awk,pl,java,c,cc,cpp,C,h,hpp},*vimrc silent call UD_UpdateInfo()
    au FileType html,xml,json set mps+=<:>
    au FileType c,cpp,java,make set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
    au FileType c,cpp set ai si ci fdm=syntax fdl=0 errorformat=%f:%l:%m path+=.,include,../include,/usr/include
endif " has (autocmd)"

"Other mappings
"<F1> - OVERRIDE Linux Help ShortKey
map <F4> <esc>:exec "help ".expand("<cword>")<cr>
"<F2> remove the multi-blanklines
map <F2> :silent! g/^\n\{1,\}$/d<cr>
"<F3> - trim trail whitespace
map <F3> :silent! g/^[ \n]\+$/d<cr>                          
"<F4> - Open/Close Insert Paste 
set pastetoggle=<F4>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。