环境:Mac OS X Yosemite

".vimrc for Mac by Haipz @haipz.com

"基础配置

set nocompatible "去掉关于vi一致性
set backspace=indent,eol,start "优化退格
call pathogen#infect() "插件管理器
syn on "语法支持
set laststatus=2 "始终显示状态栏
set tabstop=4 "一个制表符的长度
set softtabstop=4 "一个制表符的长度
set shiftwidth=4 "一个缩进的长度
set expandtab "使用空格替代制表符
set smarttab "智能制表符
set autoindent "自动缩进
set smartindent "C缩进
set number "显示行号
set ruler "显示位置指示器
"set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
set backupdir=/tmp "设置备份文件目录
set directory=/tmp "设置临时文件目录
"set nobackup "从不备份
set ignorecase "检索时忽略大小写
set hls "检索时高亮显示匹配项
set incsearch "检索时逐字高亮
set formatoptions=tcrqn "自动格式化
set gdefault "行内替换
set cmdheight=2 "命令行高度
set langmenu=zh_CN.UTF-8 "语言设置
set helplang=cn "帮助系统设置为中文
set foldmethod=syntax "代码折叠
set novisualbell "不要闪烁
set autoread "文件被改动时自动载入
set autowrite "自动保存
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容
"set guifont=Courier_New:h10:cANSI "设置字体
"colorscheme murphy "配色方案
"允许使用鼠标
set mouse=a
set selection=exclusive
set selectmode=mouse,key
set showmatch "高亮显示匹配括号
set matchtime=1 "匹配括号高亮时间
set scrolloff=3 "顶部底部保持3行距离
set wildmenu "增强模式命令行字洞完成操作
set iskeyword+=_,$,@,%,#,- "包含符号单词不背分割
set viminfo+=! "保存全局变量
set linespace=0 "字符间插入像素行数目
set whichwrap+=<,>,h,l "允许光标跨行越界
filetype on "侦测文件类型
filetype plugin on "载入缩进文件
filetype indent on "为特定文件类型载入相关缩进文件
set report=0 "获得被改变行
set history=1000 "记录历史行数
set confirm "处理未保存或只读文件时弹出确认
"在被分割窗口显示空白
set fillchars=vert:\ ,stl:\ ,stlnc:\ 
"文件编码
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8

"高级配置

"判断文件类型添加头文件
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.tex exec ":call SetTitle()"
func SetTitle()
    if (&filetype == 'sh')
        call setline(1,"\#########################################################################")
        call append(line("."),"\# File Name:".expand("%"))
        call append(line(".")+1,"\# Author: Haipz")
        call append(line(".")+2,"\# Blog: haipz.com")
        call append(line(".")+3,"\# Created Time: ".strftime("%c"))
        call append(line(".")+4,"\#########################################################################")
        call append(line(".")+5,"\#!/bin/bash")
        call append(line(".")+6,"")
    else
        call setline(1,"/*************************************************************************") 
        call append(line("."),"    > File Name: ".expand("%")) 
        call append(line(".")+1,"    > Author: Haipz") 
        call append(line(".")+2,"    > Blog: haipz.com ") 
        call append(line(".")+3,"    > Created Time: ".strftime("%c")) 
        call append(line(".")+4," ************************************************************************/") 
        call append(line(".")+5,"")
    endif
    if (&filetype == 'cpp')
        call append(line(".")+6, "#include <iostream>")
        call append(line(".")+7, "#include <string>")
        call append(line(".")+8, "#include <cstdio>")
        call append(line(".")+9, "#include <cstring>")
        call append(line(".")+10, "#include <cmath>")
        call append(line(".")+11, "#include <queue>")
        call append(line(".")+12, "#include <mat>")
        call append(line(".")+13, "#include <algorithm>")
        call append(line(".")+14, "using namespace std;")
        call append(line(".")+15, "")
    endif
    autocmd BufNewFile * normal G
endfunc

"编译代码
map <F9> :call CompileCode()<CR>
func! CompileCode()
    exec "w"
    if &filetype == 'c'
        exec "!gcc % -o %<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
    elseif &filetype == 'java' 
        exec "!javac %" 
    elseif &filetype == 'sh'
        :!./%
    endif
endfunc

"调试代码
map <F5> :call GdbCode()<CR>
func! GdbCode()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb ./%<"
endfunc

"运行代码
map <F10> :call RunCode()<CR>
func! RunCode()
    exec "w"
    if &filetype == 'c' || &filetype == 'cpp'
        exec "! ./%<"
    elseif &filetype == 'java'
        exec "!java %<"
    elseif &filetype == 'sh'
        :!./%
    endif
endfunc

"Latex配置

set grepprg=grep\ -nH\ $* "grep总是生成文件名
let g:tex_flavor='latex' "默认把空tex设为plaintex
set iskeyword+=:
autocmd BufEnter *.tex set sw=2
转载保留版权:http://haipz.com/blog/i/6286 - 海胖博客