我的gVim配置文件

13年前
"                     {/ . .\}
"                     ( (oo)   )
" +-------------oOOo---︶︶︶︶---oOOo-------------+

" @author 木木(bluedjk@163.com) QQ:498937381

" @Last Change: 2010/04/05

" 没有所谓的失败,除非你自己不再尝试,加油~!!!

" +-------------Oooo--------------------Oooo-------+

set nocompatible    "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
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

if has("gui_running")
  "设置编码格式&帮助语言
  set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
  set helplang=cn,en

  "解决菜单乱码
  set langmenu=chinese
  source $VIMRUNTIME/delmenu.vim
  source $VIMRUNTIME/menu.vim
endif

"字体设置
set guifont=Dejavu_Sans_Mono:h11:cANSI
"set gfn=YaHei\ Consolas\ Hybrid:h10
"set gfn=YaHei\ Consolas\ Hybrid:h11
"set guifontwide=YaHei\ Consolas\ Hybrid:h11
" set guifont=Courier_New:h11
" set guifontwide=YaHei\ Consolas\ Hybrid:h11

"if has("win32")
    "set guifont=Courier_New:h12:cANSI
    "set guifontwide=YouYuan:h12:cGB2312
    "au GUIEnter * simalt ~x
"elseif has("mac") || has("macunix")
"    set guifont=Courier:h14
"    set guifontwide=Hei_Regular:h14
"    colorscheme tabula
"else
"    set guifont=
"    set guifontwide=
"endif

"设置窗口的起始位置和大小
      winpos 300 200
      "winpos 250 200
      "set lines=22
      set lines=30
      set columns=100
"gvim启动最大化
    "autocmd GUIEnter * simalt ~x

"Terminal(win下的终端)
if(has("win32") || has("win95") || has("win64") || has("win16"))  
  map <C-B> :!cmd <CR>   
else  
  map <C-B> :!bash <CR>  
endif

"colorscheme Murphy                            "配色方案
"colorscheme desert
"colorscheme inkpot
"colorscheme ir_black
colorscheme koehler
"colorscheme wombat256
"set shortmess=atI                             "启动的时候不显示那个援助索马里儿童的提示
"hi Comment ctermfg=DarkCyan                   "修改默认注释颜色
syntax on                                     "语法高亮
filetype on                                   "侦测文件类型
filetype plugin on                            "载入文件类型插件
filetype indent on                            "为特定文件类型载入相关缩进文件
set showmatch                                 "高亮显示匹配的括号
set matchtime=2                               "匹配括号高亮的时间(单位是十分之一秒)
set cmdheight=2                               "命令行(在状态行下)的高度,默认为1,这里是2
set noexpandtab                               "不要用空格代替制表符
set smarttab                                  "在行和段开始处使用制表符
set wrap                                      "自动换行显示
set number                                    "显示行号儿
set report=0                                  "通过使用: commands命令,告诉我们文件的哪一行被改变过
set viminfo+=!                                "保存全局变量
set iskeyword+=_,$,@,%,#,-                    "带有如下符号的单词不要被换行分割
set backspace=2                               "使回格键(backspace)正常处理indent, eol, start等
set whichwrap+=<,>,h,l                        "允许backspace和光标键跨越行边界
set linespace=1                               "字符间插入的像素行数目
set wildmenu                                  "增强模式中的命令行自动完成操作
set nolinebreak                               "不在单词中间断行
set showcmd                                   "在状态栏显示目前所执行的指令,未完成的指令片段亦会显示出来
set backspace=indent,eol,start                "在insert模式下能用删除键进行删除
set completeopt=longest,menu                  "关掉智能补全时的预览窗口,这样可以防止闪屏现象
set textwidth=120                             "设置最大列数,超出后自动换行
set history=400                               "历史记录数
set autoread                                  "当文件在外部被修改,自动更新该文件
set gdefault                                  "行内替换
set clipboard+=unnamed                        "与windows共享剪贴板
set tabpagemax=40

"自动缩进
set autoindent  " 继承前一行的缩进方式,特别适用于多行注释
set cindent     " 使用C样式的缩进
set smartindent "为C程序提供自动缩进
set expandtab
set foldmethod=marker
    
"Tab键的宽度
set tabstop=4

"统一缩进为4
set softtabstop=4
set shiftwidth=4

"关闭备份
set nobackup
set nowritebackup
set noswapfile

"搜索忽略大小写
set ignorecase

"搜索逐字符高亮
set hlsearch
set incsearch

"设置语法折叠
set foldmethod=syntax
set foldcolumn=0 "设置折叠区域的宽度
set foldclose=all "设置为自动关闭折叠                            

"用空格键来开关折叠
set foldenable
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

"设定文件浏览器目录为当前目录
set bsdir=buffer
set autochdir

"读文件时自动设定当前目录为刚读入文件所在的目录
autocmd BufReadPost * cd %:p:h

"不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile         
set bufhidden=hide

"先尝试windows格式,再尝试unix格式,然后尝试mac格式
set fileformats=dos,unix,mac

"开启底部滚动条
"set guioptions+=b

"Set magic on
set magic

"当有错误时不发出声音
set flash
set noerrorbells
set novisualbell
set t_vb=

"使得注释换行时自动加上前导的空格和星号
set formatoptions=tcqro

"在被分割的窗口间显示空白,便于阅读
"set fillchars=vert:\ ,stl:\ ,stlnc:\

"光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3

"可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key


"我的状态行显示的内容(包括文件类型和解码)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"状态栏设置:文件路径、文件名、标记、文件类型、字符编码、文件格式、当前位置、当前相对位置、文件总行数、日期、星期
"set statusline=%F\ %h%1*%m%r%w%0*[%{strlen(&filetype)?&filetype:'none'},%{&encoding},%{&fileformat}]%=%-14.(%l,%c%V%)\ %<%p%%\ \ \ [%L]\ \ \ %{strftime('%y-%m-%d\ %A')}


"在编辑过程中,在右下角显示光标位置的状态行
    set ruler   
    set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)

"高亮鼠标位置
   if has("gui_running")  
       "cursorline  highlight(高亮当前行)
       set cursorline               
       hi CursorLine guibg=#666666
       hi CursorColumn guibg=#333333
       "cursorcolumn highlight(高亮当前列)          
       "set cursorcolumn
       "highlight CursorLine cterm=none ctermbg=2 ctermfg=0
   endif

"进入插入模式时改变状态栏颜色(仅限于Vim 7)
    "总是显示状态行
    set laststatus=2
    if version >= 700
       au InsertEnter * hi StatusLine guibg=#818D29 guifg=#FCFCFC gui=none
       au InsertLeave * hi StatusLine guibg=#EEEEEE guifg=#363636 gui=none
    endif

"用 Alt+n 切换 Vim 的标签
function! TabPos_ActivateBuffer(num)   
    let s:count = a:num    
    exe "tabfirst"   
    exe "tabnext" s:count     
endfunction   
function! TabPos_Initialize()   
    for i in range(1, 9)    
        exe "map <M-" . i . "> :call TabPos_ActivateBuffer(" . i . ")<CR>"   
    endfor   
    exe "map <M-0> :call TabPos_ActivateBuffer(10)<CR>"   
endfunction   
autocmd VimEnter * call TabPos_Initialize()

" 菜单栏和工具栏设置
"set guioptions=
"set guioptions-=m
"set guioptions-=T
map <silent> <F11> :if &guioptions =~# 'T' <Bar>
        \set guioptions-=T <Bar>
        \set guioptions-=m <bar>
    \else <Bar>
        \set guioptions+=T <Bar>
        \set guioptions+=m <Bar>
    \endif<CR>

"小菜单配置
source $VIMRUNTIME/menu.vim
set wildmenu
set cpo-=<
set wcm=<C-Z>
map <F6> :emenu <C-Z>

"tab设置
"set showtabline=2                             "显示tab
map tn :tabnext<cr>
map tp :tabprevious<cr>
map te :tabedit<cr>
map tc :tabclose<cr>
map bf :BufExplorer<cr>

"关掉智能补全时的预览窗口
set completeopt=longest,menu

"==============================插件===========================
"jsbeautify
nnoremap <F4> :call g:Jsbeautify()<CR>

"html(让html标签是小写)
let g:html_tag_case = "lowercase"

"snipMate(代码提示)
"autocomplpop(代码自动补全)


"omnicomplete
"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

"minibufexpl
    "ctrl+tab shift+ctrl+tab 切换缓冲区里的文件
     "设置用Control + [hjkl]在缓冲区窗口移动
let g:miniBufExplorerMoreThanOne=0
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
map <Leader>t :TMiniBufExplorer<cr>  "设置,t交替出现minibuffer窗口

"NERDTree 打开/关闭--文件目录树。
nmap <F3>       :NERDTreeToggle<CR>
imap <F3>  <C-O>:NERDTreeToggle<CR>

"winmanager的简单配置 通过WinManager插件来将TagList窗口和netrw窗口(浏览文件)整合起来
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
map <c-w><c-f> :FirstExplorerWindow<cr>
map <c-w><c-b> :BottomExplorerWindow<cr>
map <c-w><c-t> :WMToggle<cr>

"bufexplorer

"高亮的书签  visualmark.vim
"用gvim打开源码文件,将光标定位在需要添加书签的地方,按下ctrl+F2,即添加了书签
"使用F2在书签之间正向切换,shift+F2反向切换

"ctags(这项必须设定,否则出错,配置taglist的ctags路径)
let Tlist_Ctags_Cmd = $VIM.'\vimfiles\plugin\ctags.exe'
set tags=tags;
set autochdir
"设置tags文件路径
set tags=D:\tools\vimtags\tags

"TagList插件配置(需要安装TagList插件)
"F7打开左侧显示当前文件的函数
     nmap <F7>      :Tlist<CR>               
     imap <F7> <C-O>:Tlist<CR>
     "不同时显示多个文件的tag,只显示当前文件的
     let Tlist_Show_One_File = 1            
     "如果taglist窗口是最后一个窗口,则退出vim
     let Tlist_Exit_OnlyWindow = 1

"css3
au BufRead,BufNewFile *.css set ft=css syntax=css3

"jquery
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery

"""""""""""""""""""""代码补全(Ctrl-x+Ctrl-o和Ctrl-x+Ctrl-p能实现相关的代码补全,配置使得一个按键即可完成)"""""""""""""""""""""
"映射快捷键:<F5>实现Ctrl+x-Ctrl+o代码补全,<F5>向下切换代码补全,Alt+<F5>向上切换代码补全
inoremap <expr> <F5> pumvisible()?"\<Down>":"\<C-X><C-O>"
inoremap <expr> <M-F5> pumvisible()?"\<Up>":"\<M-F5>"

"映射快捷键:<F6>实现Ctrl+x-Ctrl+p补全,<F6>向下切换补全,Alt+<F6>向上切换补全
"inoremap <expr> <F6> pumvisible()?"\<Down>":"\<C-X><C-P>"
"inoremap <expr> <M-F6> pumvisible()?"\<Up>":"\<M-F6>"

"设置全屏快捷键
map <F12> <Esc>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>

"VSTreeExplore
map <F9> :VSTreeExplore<cr>
map <F10> :x<cr>
map <F11> :q!<cr>