我的Vimrc

本文出自:http://blog.csdn.net/svitter

本地不再更新,迁移至Svtter的github


自己的vimrc。。功能很少,持续更新。

目前支持缩进4个空格,高亮。

用了gvim的example,和bluedust的部分配置文件,用于C++的编辑。


" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <[email protected]>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Make Tab 4 space
set ts=4
set expandtab
set autoindent
"

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set background=dark
set guifont=Consolas:h11
hi clear          

hi Boolean         guifg=#dca3a3 gui=bold
hi Character       guifg=#dca3a3 gui=bold
hi Comment         guifg=#7f7f7f
hi Condtional      guifg=#8fffff
hi Constant        guifg=#dca3a3 gui=bold
hi Cursor          guifg=#000000 guibg=#aeaeae
hi Debug           guifg=#dca3a3 gui=bold
hi Define          guifg=#ffcfaf gui=bold
hi Delimiter       guifg=#8f8f8f
hi DiffAdd         guibg=#613c46
hi DiffChange      guibg=#333333
hi DiffDelete      guifg=#333333 guibg=#464646 gui=none
hi DiffText        guifg=#ffffff guibg=#1f1f1f gui=bold
hi Directory       guifg=#ffffff gui=bold
hi Error           guifg=#000000 guibg=#00ffff
hi ErrorMsg        guifg=#000000 guibg=#00c0cf
hi Exception       guifg=#8fffff gui=underline
hi Float           guifg=#9c93b3
hi FoldColumn      guifg=#dca3a3 guibg=#464646
hi Folded          guifg=#dca3a3 guibg=#333333
hi Function        guifg=#ffff8f
hi Identifier      guifg=#ffffff
hi Include         guifg=#ffcfaf gui=bold
hi IncSearch       guifg=#000000 guibg=#c15c66
hi Keyword         guifg=#ffffff gui=bold
hi Label           guifg=#8fffff gui=underline
hi LineNr          guifg=#7f7f7f guibg=#464646
hi Macro           guifg=#ffcfaf gui=bold
hi ModeMsg         guifg=#dca3a3 gui=bold
hi MoreMsg         guifg=#ffffff gui=bold
hi NonText         guifg=#1f1f1f
hi Normal          guifg=#cccccc guibg=#3f3f3f
hi Number          guifg=#aca0a3
hi Operator        guifg=#ffffff
hi PreCondit       guifg=#dfaf8f gui=bold
hi PreProc         guifg=#ffcfaf gui=bold
hi Question        guifg=#ffffff gui=bold
hi Repeat          guifg=#8fffff gui=underline
hi Search          guifg=#000000 guibg=#c15c66
hi SpecialChar     guifg=#dca3a3 gui=bold
hi SpecialComment  guifg=#dca3a3 gui=bold
hi Special         guifg=#7f7f7f
hi SpecialKey      guifg=#7e7e7e
hi Statement       guifg=#8fffff
hi StatusLine      guifg=#333333 guibg=#f18c96
hi StatusLineNC    guifg=#333333 guibg=#cccccc
hi StorageClass    guifg=#ffffff gui=bold
hi String          guifg=#cc9393
hi Structure       guifg=#ffffff gui=bold,underline
hi Tag             guifg=#dca3a3 gui=bold
hi Title           guifg=#ffffff guibg=#333333 gui=bold
hi Todo            guifg=#ffffff guibg=#000000 gui=bold
hi Typedef         guifg=#ffffff gui=bold,underline
hi Type            guifg=#ffffff gui=bold
hi VertSplit       guifg=#333333 guibg=#cccccc
hi Visual          guifg=#333333 guibg=#f18c96 gui=reverse
hi VisualNOS       guifg=#333333 guibg=#f18c96 gui=bold,underline
hi WarningMsg      guifg=#ffffff guibg=#333333 gui=bold
hi WildMenu        guifg=#000000 guibg=#dca3a3
if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif

以上是在windows下的gvim配置文件.


14.05.13更新了字体Courier 10 Pitch,行号(适用于linux):


" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <[email protected]>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Make Tab 4 space
set ts=4
set expandtab
set autoindent

set showmatch
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set background=dark
" set font
" set guifont=DejaVu\ Sans\ Mono\ 15
set guifont=Courier\ 10\ Pitch\ 15
" set curline
set cursorline
"
" set number
set number
"
hi clear         

hi Boolean         guifg=#dca3a3 gui=bold
hi Character       guifg=#dca3a3 gui=bold
hi Comment         guifg=#7f7f7f
hi Condtional      guifg=#8fffff
hi Constant        guifg=#dca3a3 gui=bold
hi Cursor          guifg=#000000 guibg=#aeaeae
hi Debug           guifg=#dca3a3 gui=bold
hi Define          guifg=#ffcfaf gui=bold
hi Delimiter       guifg=#8f8f8f
hi DiffAdd         guibg=#613c46
hi DiffChange      guibg=#333333
hi DiffDelete      guifg=#333333 guibg=#464646 gui=none
hi DiffText        guifg=#ffffff guibg=#1f1f1f gui=bold
hi Directory       guifg=#ffffff gui=bold
hi Error           guifg=#000000 guibg=#00ffff
hi ErrorMsg        guifg=#000000 guibg=#00c0cf
hi Exception       guifg=#8fffff gui=underline
hi Float           guifg=#9c93b3
hi FoldColumn      guifg=#dca3a3 guibg=#464646
hi Folded          guifg=#dca3a3 guibg=#333333
hi Function        guifg=#ffff8f
hi Identifier      guifg=#ffffff
hi Include         guifg=#ffcfaf gui=bold
hi IncSearch       guifg=#000000 guibg=#c15c66
hi Keyword         guifg=#ffffff gui=bold
hi Label           guifg=#8fffff gui=underline
hi LineNr          guifg=#7f7f7f guibg=#464646
hi Macro           guifg=#ffcfaf gui=bold
hi ModeMsg         guifg=#dca3a3 gui=bold
hi MoreMsg         guifg=#ffffff gui=bold
hi NonText         guifg=#1f1f1f
hi Normal          guifg=#cccccc guibg=#3f3f3f
hi Number          guifg=#aca0a3
hi Operator        guifg=#ffffff
hi PreCondit       guifg=#dfaf8f gui=bold
hi PreProc         guifg=#ffcfaf gui=bold
hi Question        guifg=#ffffff gui=bold
hi Repeat          guifg=#8fffff gui=underline
hi Search          guifg=#000000 guibg=#c15c66
hi SpecialChar     guifg=#dca3a3 gui=bold
hi SpecialComment  guifg=#dca3a3 gui=bold
hi Special         guifg=#7f7f7f
hi SpecialKey      guifg=#7e7e7e
hi Statement       guifg=#8fffff
hi StatusLine      guifg=#333333 guibg=#f18c96
hi StatusLineNC    guifg=#333333 guibg=#cccccc
hi StorageClass    guifg=#ffffff gui=bold
hi String          guifg=#cc9393
hi Structure       guifg=#ffffff gui=bold,underline
hi Tag             guifg=#dca3a3 gui=bold
hi Title           guifg=#ffffff guibg=#333333 gui=bold
hi Todo            guifg=#ffffff guibg=#000000 gui=bold
hi Typedef         guifg=#ffffff gui=bold,underline
hi Type            guifg=#ffffff gui=bold
hi VertSplit       guifg=#333333 guibg=#cccccc
hi Visual          guifg=#333333 guibg=#f18c96 gui=reverse
hi VisualNOS       guifg=#333333 guibg=#f18c96 gui=bold,underline
hi WarningMsg      guifg=#ffffff guibg=#333333 gui=bold
hi WildMenu        guifg=#000000 guibg=#dca3a3
if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif


Linux:

在以上的基础上添加了文件目录NERDtree,c/c++程序的一键编译。

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <[email protected]>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Make Tab 4 space
set ts=4
set expandtab
set autoindent
"
set showmatch
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set background=dark
" set font
" set guifont=DejaVu\ Sans\ Mono\ 15 
set guifont=Courier\ 10\ Pitch\ 12
" set curline
set cursorline
"
" set number
set number
" set fileon
filetype on
" 打开折叠
map <F3> zO
" 关闭折叠    
map <F4> zc
" 打开所有折叠
map <F5> zR
" 关闭所有折叠
map <F6> zM
"
hi clear         

hi Boolean         guifg=#dca3a3 gui=bold
hi Character       guifg=#dca3a3 gui=bold
hi Comment         guifg=#7f7f7f
hi Condtional      guifg=#8fffff
hi Constant        guifg=#dca3a3 gui=bold
hi Cursor          guifg=#000000 guibg=#aeaeae
hi Debug           guifg=#dca3a3 gui=bold
hi Define          guifg=#ffcfaf gui=bold
hi Delimiter       guifg=#8f8f8f
hi DiffAdd         guibg=#613c46
hi DiffChange      guibg=#333333
hi DiffDelete      guifg=#333333 guibg=#464646 gui=none
hi DiffText        guifg=#ffffff guibg=#1f1f1f gui=bold
hi Directory       guifg=#ffffff gui=bold
hi Error           guifg=#000000 guibg=#00ffff
hi ErrorMsg        guifg=#000000 guibg=#00c0cf
hi Exception       guifg=#8fffff gui=underline
hi Float           guifg=#9c93b3
hi FoldColumn      guifg=#dca3a3 guibg=#464646
hi Folded          guifg=#dca3a3 guibg=#333333
hi Function        guifg=#ffff8f
hi Identifier      guifg=#ffffff
hi Include         guifg=#ffcfaf gui=bold
hi IncSearch       guifg=#000000 guibg=#c15c66
hi Keyword         guifg=#ffffff gui=bold
hi Label           guifg=#8fffff gui=underline
hi LineNr          guifg=#7f7f7f guibg=#464646
hi Macro           guifg=#ffcfaf gui=bold
hi ModeMsg         guifg=#dca3a3 gui=bold
hi MoreMsg         guifg=#ffffff gui=bold
hi NonText         guifg=#1f1f1f
hi Normal          guifg=#cccccc guibg=#3f3f3f
hi Number          guifg=#aca0a3
hi Operator        guifg=#ffffff
hi PreCondit       guifg=#dfaf8f gui=bold
hi PreProc         guifg=#ffcfaf gui=bold
hi Question        guifg=#ffffff gui=bold
hi Repeat          guifg=#8fffff gui=underline
hi Search          guifg=#000000 guibg=#c15c66
hi SpecialChar     guifg=#dca3a3 gui=bold
hi SpecialComment  guifg=#dca3a3 gui=bold
hi Special         guifg=#7f7f7f
hi SpecialKey      guifg=#7e7e7e
hi Statement       guifg=#8fffff
hi StatusLine      guifg=#333333 guibg=#f18c96
hi StatusLineNC    guifg=#333333 guibg=#cccccc
hi StorageClass    guifg=#ffffff gui=bold
hi String          guifg=#cc9393
hi Structure       guifg=#ffffff gui=bold,underline
hi Tag             guifg=#dca3a3 gui=bold
hi Title           guifg=#ffffff guibg=#333333 gui=bold
hi Todo            guifg=#ffffff guibg=#000000 gui=bold
hi Typedef         guifg=#ffffff gui=bold,underline
hi Type            guifg=#ffffff gui=bold
hi VertSplit       guifg=#333333 guibg=#cccccc
hi Visual          guifg=#333333 guibg=#f18c96 gui=reverse
hi VisualNOS       guifg=#333333 guibg=#f18c96 gui=bold,underline
hi WarningMsg      guifg=#ffffff guibg=#333333 gui=bold
hi WildMenu        guifg=#000000 guibg=#dca3a3
if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.  Use the default filetype settings, so that
  " mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif


" NERDtree
"
" How can I open a NERDTree automatically when vim starts up?"
" autocmd vimenter * NERDTree
" How can I open a NERDTree automatically when vim starts up if no files were specified?
autocmd vimenter * if !argc() | NERDTree | endif

set autochdir
autocmd BufEnter * silent! lcd %:p:h

" Using the autocmd method, you could customize when the directory change takes place. For example, to not change directory if the file is in /tmp:
autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | silent! lcd %:p:h | endif

" 初始位置,初始大小
winpos 100 100 
set lines=25 columns=108
"------------------------------------------------------------------------------
"  < 判断操作系统是否是 Windows 还是 Linux >
"------------------------------------------------------------------------------
if(has("win32") || has("win64") || has("win95") || has("win16"))
    let g:iswindows = 1
else
    let g:iswindows = 0
endif

" auto compiler
"------------------------------------------------------------------------------
"  < 判断是终端还是 Gvim >
"------------------------------------------------------------------------------
if has("gui_running")
    let g:isGUI = 1
else
    let g:isGUI = 0
endif

"------------------------------------------------------------------------------
"  < 编译、连接、运行配置 >
"------------------------------------------------------------------------------
" F9 一键保存、编译、连接存并运行
map <F9> :call Run()<CR>
imap <F9> <ESC>:call Run()<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! Run()
    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


2014.5.28:

增加了C缩进,另外如果需要NERDtree需要另外下载;

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <[email protected]>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
"
"
"
" Make Tab 4 space
set ts=4
set expandtab
set autoindent
set softtabstop=4
set shiftwidth=4
set cindent
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
"
"
"
"
"
set showmatch
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set background=dark
" set font
" set guifont=DejaVu\ Sans\ Mono\ 15 
set guifont=Courier\ 10\ Pitch\ 12
" set curline
set cursorline
"
" set number
set number
" set fileon
filetype on
" 打开折叠
map <F3> zO
" 关闭折叠    
map <F4> zc
" 打开所有折叠
map <F5> zR
" 关闭所有折叠
map <F6> zM
"
hi clear         

hi Boolean         guifg=#dca3a3 gui=bold
hi Character       guifg=#dca3a3 gui=bold
hi Comment         guifg=#7f7f7f
hi Condtional      guifg=#8fffff
hi Constant        guifg=#dca3a3 gui=bold
hi Cursor          guifg=#000000 guibg=#aeaeae
hi Debug           guifg=#dca3a3 gui=bold
hi Define          guifg=#ffcfaf gui=bold
hi Delimiter       guifg=#8f8f8f
hi DiffAdd         guibg=#613c46
hi DiffChange      guibg=#333333
hi DiffDelete      guifg=#333333 guibg=#464646 gui=none
hi DiffText        guifg=#ffffff guibg=#1f1f1f gui=bold
hi Directory       guifg=#ffffff gui=bold
hi Error           guifg=#000000 guibg=#00ffff
hi ErrorMsg        guifg=#000000 guibg=#00c0cf
hi Exception       guifg=#8fffff gui=underline
hi Float           guifg=#9c93b3
hi FoldColumn      guifg=#dca3a3 guibg=#464646
hi Folded          guifg=#dca3a3 guibg=#333333
hi Function        guifg=#ffff8f
hi Identifier      guifg=#ffffff
hi Include         guifg=#ffcfaf gui=bold
hi IncSearch       guifg=#000000 guibg=#c15c66
hi Keyword         guifg=#ffffff gui=bold
hi Label           guifg=#8fffff gui=underline
hi LineNr          guifg=#7f7f7f guibg=#464646
hi Macro           guifg=#ffcfaf gui=bold
hi ModeMsg         guifg=#dca3a3 gui=bold
hi MoreMsg         guifg=#ffffff gui=bold
hi NonText         guifg=#1f1f1f
hi Normal          guifg=#cccccc guibg=#3f3f3f
hi Number          guifg=#aca0a3
hi Operator        guifg=#ffffff
hi PreCondit       guifg=#dfaf8f gui=bold
hi PreProc         guifg=#ffcfaf gui=bold
hi Question        guifg=#ffffff gui=bold
hi Repeat          guifg=#8fffff gui=underline
hi Search          guifg=#000000 guibg=#c15c66
hi SpecialChar     guifg=#dca3a3 gui=bold
hi SpecialComment  guifg=#dca3a3 gui=bold
hi Special         guifg=#7f7f7f
hi SpecialKey      guifg=#7e7e7e
hi Statement       guifg=#8fffff
hi StatusLine      guifg=#333333 guibg=#f18c96
hi StatusLineNC    guifg=#333333 guibg=#cccccc
hi StorageClass    guifg=#ffffff gui=bold
hi String          guifg=#cc9393
hi Structure       guifg=#ffffff gui=bold,underline
hi Tag             guifg=#dca3a3 gui=bold
hi Title           guifg=#ffffff guibg=#333333 gui=bold
hi Todo            guifg=#ffffff guibg=#000000 gui=bold
hi Typedef         guifg=#ffffff gui=bold,underline
hi Type            guifg=#ffffff gui=bold
hi VertSplit       guifg=#333333 guibg=#cccccc
hi Visual          guifg=#333333 guibg=#f18c96 gui=reverse
hi VisualNOS       guifg=#333333 guibg=#f18c96 gui=bold,underline
hi WarningMsg      guifg=#ffffff guibg=#333333 gui=bold
hi WildMenu        guifg=#000000 guibg=#dca3a3
if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.  Use the default filetype settings, so that
  " mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif


" NERDtree
"
" How can I open a NERDTree automatically when vim starts up?"
" autocmd vimenter * NERDTree
" How can I open a NERDTree automatically when vim starts up if no files were specified?
autocmd vimenter * if !argc() | NERDTree | endif

set autochdir
autocmd BufEnter * silent! lcd %:p:h

" Using the autocmd method, you could customize when the directory change takes place. For example, to not change directory if the file is in /tmp:
autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | silent! lcd %:p:h | endif

" 初始位置,初始大小
winpos 100 100 
set lines=25 columns=108
"------------------------------------------------------------------------------
"  < 判断操作系统是否是 Windows 还是 Linux >
"------------------------------------------------------------------------------
if(has("win32") || has("win64") || has("win95") || has("win16"))
    let g:iswindows = 1
else
    let g:iswindows = 0
endif

" auto compiler
"------------------------------------------------------------------------------
"  < 判断是终端还是 Gvim >
"------------------------------------------------------------------------------
if has("gui_running")
    let g:isGUI = 1
else
    let g:isGUI = 0
endif

"------------------------------------------------------------------------------
"  < 编译、连接、运行配置 >
"------------------------------------------------------------------------------
" F9 一键保存、编译、连接存并运行
map <F9> :call Run()<CR>
imap <F9> <ESC>:call Run()<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! Run()
    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


你可能感兴趣的:(vim)