我的Vim配置文件

"------------------------------------------------------------------------------
"  操作系统 
"------------------------------------------------------------------------------
if(has("win32") || has("win64"))
    let g:iswindows = 1
else
    let g:iswindows = 0
endif

"------------------------------------------------------------------------------
"是否为终端运行
"------------------------------------------------------------------------------
if has("gui_running")
    let g:isGUI = 1
else
    let g:isGUI = 0
endif

"------------------------------------------------------------------------------
" 设置字体
"------------------------------------------------------------------------------
if g:iswindows
    set guifont=Monaco:h11:cANSI
else
    set guifontwide=Monaco\ Hybrid:h10
endif

filetype plugin on
autocmd! bufwritepost _vimrc source %  "autoload _vimrc when it changed
au BufNewFile,BufRead *.ahk setf ahk   "Autohotkey synax file
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery "jquery synax file
"au FileType php setlocal dict+=$VIM/vimfiles/dictionary/php_func.txt

syn on
colo desert  "colorscheme setting 
set ai!      "auto indent
set nocompatible
set nobackup          "no backup automent
set number
set fileencodings=utf8,gbk.ucs-bom,cp936
set shiftwidth=4
set tabstop=4          "tab's width
set softtabstop=4      "tab's width
set expandtab
set autoindent
set guitablabel=%{tabpagenr()}.%t\ %m "tab display
set history=50      "history record steps
set hid             " allow switching buffers, which have unsaved changes
set ruler           " show the cursor position all the time
set incsearch        " do incremental searching
set nohlsearch        " no hightline for the match word when search
set ignorecase        " ignore case
set smartcase        " but don't ignore it, when search string contains uppercase letters
set showmatch        " showmatch: Show the matching bracket for the last ')'?
set shiftwidth=4    " 4 characters for indenting
set completeopt=menu,longest,preview
set backspace=indent,eol,start whichwrap+=<,>,[,] "enable the backspace
set vb t_vb=
set nowrap
set noerrorbells    " No sound on errors.
set novisualbell
set cursorline      "hightline the current line
set ignorecase      "unsensitive of case  when search
set showcmd         "show the current command 
set go-=L
set go-=l           "unable the scroll bar
set go-=r
set go-=R
set go-=T           "hide the toolbar
set go-=m           "hide the toolbar
set fdm=manual      "fold method: indent;expr;syntax;diff;marker
set noequalalways
set nocompatible
set ff=unix
let &termencoding=&encoding


"------------------------------------------------------------------------------
" Keymap
"------------------------------------------------------------------------------
map tl :tabnext<CR>
map th :tabpre<CR>
map tn :tabnew<CR>
map tc :tabclose<CR>
map <F2> :NERDTreeToggle<CR>
map <F3> :TlistToggle<CR>
nmap <F4> :AuthorInfoDetect<cr> 
map <F5> :call Run()<CR>
map <F6> :call CheckPHPSyntax()<CR>
map <F7> :mkv<CR>
map <F12> :source Session.vim<CR>

abbr for(  for(i = 0;i<!cursor!;i++){<CR><CR>}<Esc>:call search ('!cursor!','b')<cr>cf!
abbr <?p   <?php !cursor! ?><Esc>:call search('!cursor!','b')<CR>cf! 


" setting for Author Profile
let g:vimrc_author='Carlos Wong' 
let g:vimrc_email='2carlos.wong@gmail.com' 
let g:vimrc_homepage='http://www.tieniuzai.com' 

"------------------------------------------------------------------------------
" NERDTree 
"------------------------------------------------------------------------------
let NERDTreeWinPos = 1
let NERDTreeWinSize =20
let NERDChristmasTree= 1

"------------------------------------------------------------------------------
" set startup for neocomplcache
"------------------------------------------------------------------------------
let g:neocomplcache_enable_at_startup = 1

"------------------------------------------------------------------------------
" Taglist support by ctags
"------------------------------------------------------------------------------
if g:iswindows
    let g:Tlist_Ctags_Cmd = 'ctags.exe'
else
    let g:Tlist_Ctags_Cmd = '/usr/bin/ctags'
endif 
let Tlist_Show_One_File = 1    
let tlist_php_settings='php;c:Classes;f:Functions;d:Constants;j:Javascript Functions'

"------------------------------------------------------------------------------
" Setting for ctrlp
"------------------------------------------------------------------------------
if g:iswindows
    set wildignore+=tmp\*,*.swp,*.zip,*.exe,*.pyc
endif
let g:ctrlp_map='<c-p>'
let g:ctrlp_working_path_mode=1
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$|\.idea$'
let g:ctrlp_clear_cache_on_exit=0
let g:ctrlp_use_caching=1
let g:ctrlp_max_files=0
let g:ctrlp_cmd = 'CtrlPCurWD'

"------------------------------------------------------------------------------
" Setting for tabbar
"------------------------------------------------------------------------------
let g:Tb_UseSingleClick = 1

"------------------------------------------------------------------------------
" vimim
"------------------------------------------------------------------------------
let g:vimim_cloud = 0
let g:vimim_enable_smart_space = 1

"------------------------------------------------------------------------------
" IndentGUide
"------------------------------------------------------------------------------
let g:indent_guides_enable_on_vim_startup = 1

"------------------------------------------------------------------------------
" 检查PHP语法
"------------------------------------------------------------------------------
function! CheckPHPSyntax()
    if &filetype != 'php'
        echohl WarningMsg | echo 'This is not a PHP file !' | echohl None
        return
    endif
    setlocal makeprg=php\ -l\ -n\ -d\ html_errors=off\ %
    setlocal errorformat=%m\ in\ %f\ on\ line\ %l
    echohl WarningMsg | echo 'Syntax Checking:' | echohl None
    if &modified == 1
       silent write
    endif
    silent make
            clist
endfunction

function! Run()
    exec 'w'
    if &filetype == 'c'
        call RunCpp()
    elseif &filetype =='cpp'
        call RunCpp()
    elseif &filetype =='java'
        exec "!java %<"
    elseif &filetype =='python'
        exec "!python %<.py"
    elseif &filetype =='ruby'
        exec "!ruby %<.rb"
    elseif &filetype =='php'
        exec "!php %<.php"
    endif
endfunc

"------------------------------------------------------------------------------
" C/C++编译、链接、运行
"------------------------------------------------------------------------------
" F9编译链接运行
map <F9> :call RunCpp()<CR>
imap <F9> <ESC>:call RunCpp()<CR>

" Ctrl + F9 编译
map <c-F9> :call Compile()<CR>
imap <c-F9> <ESC>:call Compile()<CR>

" Ctrl + F10 链接
map <c-F10> :call Link()<CR>
imap <c-F10> <ESC>:call Link()<CR>

let s:LastShellReturn_C = 0
let s:LastShellReturn_L = 0
let s:ShowWarning = 1
let s:Obj_Extension = '.o'
let s:Exe_Extension = '.exe'
let s:Sou_Error = 0

let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:linux_CFlags = 'gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'

let s:windows_CPPFlags = 'g++\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:linux_CPPFlags = 'g++\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'

func! Compile()
    exe ":ccl"
    exe ":update"
    if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
        let s:Sou_Error = 0
        let s:LastShellReturn_C = 0
        let Sou = expand("%:p")
        let Obj = expand("%:p:r").s:Obj_Extension
        let Obj_Name = expand("%:p:t:r").s:Obj_Extension
        let v:statusmsg = ''
        if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))
            redraw!
            if expand("%:e") == "c"
                if g:iswindows
                    exe ":setlocal makeprg=".s:windows_CFlags
                else
                    exe ":setlocal makeprg=".s:linux_CFlags
                endif
                echohl WarningMsg | echo " compiling..."
                silent make
            elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
                if g:iswindows
                    exe ":setlocal makeprg=".s:windows_CPPFlags
                else
                    exe ":setlocal makeprg=".s:linux_CPPFlags
                endif
                echohl WarningMsg | echo " compiling..."
                silent make
            endif
            redraw!
            if v:shell_error != 0
                let s:LastShellReturn_C = v:shell_error
            endif
            if g:iswindows
                if s:LastShellReturn_C != 0
                    exe ":bo cope"
                    echohl WarningMsg | echo " compilation failed"
                else
                    if s:ShowWarning
                        exe ":bo cw"
                    endif
                    echohl WarningMsg | echo " compilation successful"
                endif
            else
                if empty(v:statusmsg)
                    echohl WarningMsg | echo " compilation successful"
                else
                    exe ":bo cope"
                endif
            endif
        else
            echohl WarningMsg | echo ""Obj_Name"is up to date"
        endif
    else
        let s:Sou_Error = 1
        echohl WarningMsg | echo " please choose the correct source file"
    endif
    exe ":setlocal makeprg=make"
endfunc

func! Link()
    call Compile()
    if s:Sou_Error || s:LastShellReturn_C != 0
        return
    endif
    let s:LastShellReturn_L = 0
    let Sou = expand("%:p")
    let Obj = expand("%:p:r").s:Obj_Extension
    if g:iswindows
        let Exe = expand("%:p:r").s:Exe_Extension
        let Exe_Name = expand("%:p:t:r").s:Exe_Extension
    else
        let Exe = expand("%:p:r")
        let Exe_Name = expand("%:p:t:r")
    endif
    let v:statusmsg = ''
    if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))
        redraw!
        if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))
            if expand("%:e") == "c"
                setlocal makeprg=gcc\ -o\ %<\ %<.o
                echohl WarningMsg | echo " linking..."
                silent make
            elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
                setlocal makeprg=g++\ -o\ %<\ %<.o
                echohl WarningMsg | echo " linking..."
                silent make
            endif
            redraw!
            if v:shell_error != 0
                let s:LastShellReturn_L = v:shell_error
            endif
            if g:iswindows
                if s:LastShellReturn_L != 0
                    exe ":bo cope"
                    echohl WarningMsg | echo " linking failed"
                else
                    if s:ShowWarning
                        exe ":bo cw"
                    endif
                    echohl WarningMsg | echo " linking successful"
                endif
            else
                if empty(v:statusmsg)
                    echohl WarningMsg | echo " linking successful"
                else
                    exe ":bo cope"
                endif
            endif
        else
            echohl WarningMsg | echo ""Exe_Name"is up to date"
        endif
    endif
    setlocal makeprg=make
endfunc

func! RunCpp()
    let s:ShowWarning = 0
    call Link()
    let s:ShowWarning = 1
    if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0
        return
    endif
    let Sou = expand("%:p")
    let Obj = expand("%:p:r").s:Obj_Extension
    if g:iswindows
        let Exe = expand("%:p:r").s:Exe_Extension
    else
        let Exe = expand("%:p:r")
    endif
    if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)
        redraw!
        echohl WarningMsg | echo " running..."
        if g:iswindows
            exe ":!%<.exe"
        else
            if g:isGUI
                exe ":!gnome-terminal -e ./%<"
            else
                exe ":!./%<"
            endif
        endif
        redraw!
        echohl WarningMsg | echo " running finish"
    endif
endfunc
posted @ 2013-04-20 12:47  铁牛仔  阅读(331)  评论(0)    收藏  举报