Created
April 23, 2012 08:57
-
-
Save yaonie/2469674 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ----------------- http://yaonie.org | |
" ----------------- Date: 2011-08-04 | |
set nocompatible | |
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 | |
" 配色方案 | |
colorscheme desert " 灰褐色 | |
" 字体、字号 | |
set guifont=Monaco:h10 | |
set tabstop=4 " 设置tab键的宽度 | |
set shiftwidth=4 " 换行时行间交错使用4个空格 | |
set autoindent " 自动对齐 | |
set backspace=2 " 设置退格键可用 | |
set cindent shiftwidth=4 " 自动缩进4空格 | |
set smartindent " 智能自动缩进 | |
set ai! " 设置自动缩进 | |
set nu! " 显示行号 | |
"set showmatch " 显示括号配对情况 | |
set mouse=a " 启用鼠标 | |
set ruler " 右下角显示光标位置的状态行 | |
set incsearch " 查找book时,当输入/b时会自动找到 | |
set hlsearch " 开启高亮显示结果 | |
set incsearch " 开启实时搜索功能 | |
set nowrapscan " 搜索到文件两端时不重新搜索 | |
"set nocompatible " 关闭兼容模式 | |
set vb t_vb= " 关闭提示音 | |
set cursorline " 突出显示当前行 | |
set hidden " 允许在有未保存的修改时切换缓冲区 | |
set list " 显示Tab符,使用一高亮竖线代替 | |
set listchars=tab:\|\ , | |
set clipboard+=unnamed "设置与windows共享剪切板 | |
syntax enable " 打开语法高亮 | |
syntax on " 开启文件类型侦测 | |
filetype indent on " 针对不同的文件类型采用不同的缩进格式 | |
filetype plugin on " 针对不同的文件类型加载对应的插件 | |
filetype plugin indent on | |
if has("gui_running") | |
au GUIEnter * simalt ~x " 窗口启动时自动最大化 | |
"set guioptions-=m " 隐藏菜单栏 | |
set guioptions-=T " 隐藏工具栏 | |
"set guioptions-=L " 隐藏左侧滚动条 | |
"set guioptions-=r " 隐藏右侧滚动条 | |
"set guioptions-=b " 隐藏底部滚动条 | |
"set showtabline=0 " 隐藏Tab栏 | |
endif | |
set writebackup " 设置无备份文件 | |
set noswapfile " 设置不生成.swp临时文件 | |
set nobackup | |
set autochdir " 设定文件浏览器目录为当前目录 | |
"set nowrap " 设置不自动换行 | |
set foldmethod=syntax " 选择代码折叠类型 | |
set foldlevel=100 " 禁止自动折叠 | |
" 每行超过80个的字符用下划线标示 | |
au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/ | |
" 编码设置 | |
"set encoding=utf-8 | |
set fileencodings=utf-8,cp936,gbk,gb18030,big5,latin1 | |
" For Haskell | |
:let hs_highlight_delimiters=1 " 高亮定界符 | |
:let hs_highlight_boolean=1 " 把True和False识别为关键字 | |
:let hs_highlight_types=1 " 把基本类型的名字识别为关键字 | |
:let hs_highlight_more_types=1 " 把更多常用类型识别为关键字 | |
:let hs_highlight_debug=1 " 高亮调试函数的名字 | |
:let hs_allow_hash_operator=1 " 阻止把#高亮为错误 | |
set laststatus=2 " 开启状态栏信息 | |
set cmdheight=2 " 命令行的高度,默认为1,这里设为2 | |
" 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等] | |
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} | |
" ######### 括号、引号、中括号等自动匹配 ######### " | |
:inoremap ( ()<ESC>i | |
:inoremap ) <c-r>=ClosePair(')')<CR> | |
:inoremap { {}<ESC>i | |
:inoremap } <c-r>=ClosePair('}')<CR> | |
:inoremap [ []<ESC>i | |
:inoremap ] <c-r>=ClosePair(']')<CR> | |
":inoremap < <><ESC>i | |
":inoremap > <c-r>=ClosePair('>')<CR> | |
:inoremap " ""<ESC>i | |
:inoremap ' ''<ESC>i | |
:inoremap ` ``<ESC>i | |
function ClosePair(char) | |
if getline('.')[col('.') - 1] == a:char | |
return "\<Right>" | |
else | |
return a:char | |
endif | |
endf | |
" ######### 一键保存和编译 ######### " | |
" ######### 如此处没有配置你需要的编程语言,请参照示例自行配置,很简单的 | |
" 编译C源文件 | |
func! CompileGcc() | |
exec "w" | |
let compilecmd="!gcc -Wall -pedantic -std=c99 " | |
let compileflag="-o %<" | |
exec compilecmd." % ".compileflag | |
endfunc | |
" 编译C++源文件 | |
func! CompileCpp() | |
exec "w" | |
let compilecmd="!g++ -Wall -pedantic -std=c++98 " | |
let compileflag="-o %<" | |
exec compilecmd." % ".compileflag | |
endfunc | |
" 编译Java源文件 | |
func! CompileJava() | |
exec "w" | |
exec "!javac %" | |
endfunc | |
" 编译Haskell源文件 | |
func! CompileHaskell() | |
exec "w" | |
let compilecmd="!ghc --make " | |
let compileflag="-o %<" | |
exec compilecmd." % ".compileflag | |
endfunc | |
" 运行Lua源文件 | |
func! RunLua() | |
exec "w" | |
exec "!lua %" | |
endfunc | |
" 运行Perl源文件 | |
func! RunPerl() | |
exec "w" | |
exec "!perl %" | |
endfunc | |
" 运行Python源文件 | |
func! RunPython() | |
exec "w" | |
exec "!python %" | |
endfunc | |
" 运行Ruby源文件 | |
func! RunRuby() | |
exec "w" | |
exec "!ruby %" | |
endfunc | |
" 根据文件类型自动选择相应的编译函数 | |
func! CompileCode() | |
exec "w" | |
if &filetype == "c" | |
exec "call CompileGcc()" | |
elseif &filetype == "cpp" | |
exec "call CompileCpp()" | |
elseif &filetype == "java" | |
exec "call CompileJava()" | |
elseif &filetype == "haskell" | |
exec "call CompileHaskell()" | |
elseif &filetype == "lua" | |
exec "call RunLua()" | |
elseif &filetype == "perl" | |
exec "call RunPerl()" | |
elseif &filetype == "python" | |
exec "call RunPython()" | |
elseif &filetype == "ruby" | |
exec "call RunRuby()" | |
endif | |
endfunc | |
" 运行可执行文件 | |
func! RunResult() | |
exec "w" | |
if &filetype == "c" | |
exec "! %<" | |
elseif &filetype == "cpp" | |
exec "! %<" | |
elseif &filetype == "java" | |
exec "!java %<" | |
elseif &filetype == "haskell" | |
exec "! %<" | |
elseif &filetype == "lua" | |
exec "!lua %<.lua" | |
elseif &filetype == "perl" | |
exec "!perl %<.pl" | |
elseif &filetype == "python" | |
exec "!python %<.py" | |
elseif &filetype == "ruby" | |
exec "!ruby %<.rb" | |
endif | |
endfunc | |
" Ctrl + C 一键保存、编译 | |
"map :call CompileCode()<CR> | |
"imap <ESC>:call CompileCode()<CR> | |
"vmap <ESC>:call CompileCode()<CR> | |
" Ctrl + R 一键保存、运行 | |
map :call RunResult()<CR> | |
imap <ESC>:call RunResult()<CR> | |
vmap <ESC>:call RunResult()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment