Created
November 2, 2010 08:17
-
-
Save caingougou/659365 to your computer and use it in GitHub Desktop.
vim配置文件
This file contains 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
if v:version < 700 | |
echoerr 'This _vimrc requires Vim 7 or later.' | |
quit | |
endif | |
" 获取当前目录 | |
func! GetPWD() | |
return substitute(getcwd(), "", "", "g") | |
endf | |
" 跳过页头注释,到首行实际代码 | |
func! GotoFirstEffectiveLine() | |
let l:c = 0 | |
while l:c<line("$") && ( | |
\ getline(l:c) =~ '^\s*$' | |
\ || synIDattr(synID(l:c, 1, 0), "name") =~ ".*Comment.*" | |
\ || synIDattr(synID(l:c, 1, 0), "name") =~ ".*PreProc$" | |
\ ) | |
let l:c = l:c+1 | |
endwhile | |
exe "normal ".l:c."Gz\<CR>" | |
endf | |
" 全选 | |
func! SelectAll() | |
let s:current = line('.') | |
exe "norm gg" . (&slm == "" ? "VG" : "gH\<C-O>G") | |
endfunc | |
" From an idea by Michael Naumann | |
func! VisualSearch(direction) range | |
let l:saved_reg = @" | |
execute "normal! vgvy" | |
let l:pattern = escape(@", '\\/.*$^~[]') | |
let l:pattern = substitute(l:pattern, "\n$", "", "") | |
if a:direction == 'b' | |
execute "normal ?" . l:pattern . "^M" | |
elseif a:direction == 'gv' | |
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.') | |
elseif a:direction == 'f' | |
execute "normal /" . l:pattern . "^M" | |
endif | |
let @/ = l:pattern | |
let @" = l:saved_reg | |
endfunc | |
" ========= | |
" 环境配置 | |
" ========= | |
set nocompatible | |
" 保留历史记录 | |
set history=700 | |
" 文件格式 | |
filetype plugin indent on | |
" 行控制 | |
set linebreak | |
set textwidth=80 | |
set wrap | |
" 标签页 | |
set tabpagemax=9 | |
set showtabline=2 | |
" 控制台响铃 | |
set noerrorbells | |
set novisualbell | |
set t_vb= "close visual bell | |
" 行号和标尺 | |
set number | |
set ruler | |
set rulerformat=%15(%c%V\ %p%%%) | |
" 命令行于状态行 | |
set ch=1 | |
set stl=\ [File]\ %F%m%r%h%y[%{&fileformat},%{&fileencoding}]\ %w\ \ [PWD]\ %r%{GetPWD()}%h\ %=\ [Line]%l/%L\ %=\[%P] | |
set ls=2 " 始终显示状态行 | |
" Search Option | |
set hlsearch "Highlight search things | |
set magic "Set magic on, for regular expressions | |
set showmatch "Show matching bracets when text indicator is over them | |
set mat=8 "How many tenths of a second to blink | |
set incsearch | |
set ignorecase | |
" 制表符 | |
set tabstop=4 | |
set expandtab | |
set smarttab | |
set shiftwidth=4 | |
set softtabstop=4 | |
" 状态栏显示目前所执行的指令 | |
set showcmd | |
" 缩进 | |
set autoindent | |
set smartindent | |
" 自动重新读入 | |
set autoread | |
" 插入模式下使用 <BS>、<Del> <C-W> <C-U> | |
set backspace=indent,eol,start | |
" 设定在任何模式下鼠标都可用 | |
set mouse=a | |
" 备份和缓存 | |
" set nobackup | |
set backup | |
set backupdir=~/.vim/bak | |
autocmd BufwritePre * let &backupext = strftime(".%Y-%m-%d-%H-%M") | |
set noswapfile | |
" 自动完成 | |
set complete=.,w,b,k,t,i | |
set completeopt=longest,menu | |
" 代码折叠 | |
set nofoldenable | |
set foldmethod=syntax | |
" 保证语法高亮 | |
syntax on | |
" ===================== | |
" 多语言环境 | |
" 默认为 UTF-8 编码 | |
" ===================== | |
if has("multi_byte") | |
set encoding=utf-8 | |
" English messages only | |
"language messages zh_CN.utf-8 | |
if has('win32') | |
language english | |
let &termencoding=&encoding | |
endif | |
set fencs=utf-8,gbk,chinese,latin1 | |
set formatoptions+=mM | |
set nobomb " 不使用 Unicode 签名 | |
if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)' | |
set ambiwidth=double | |
endif | |
else | |
echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" | |
endif | |
" ========= | |
" 图形界面 | |
" ========= | |
if has('gui_running') | |
" 只显示菜单 | |
set guioptions=cr | |
if has('gui_macvim') | |
set guioptions+=e | |
endif | |
" 高亮光标所在的行 | |
set cursorline | |
" 编辑器配色 | |
colorscheme desert256 | |
set background=dark | |
if has("win32") | |
" Windows 兼容配置 | |
source $VIMRUNTIME/mswin.vim | |
" f11 最大化 | |
map <f11> :call libcallnr('fullscreen.dll', 'ToggleFullScreen', 0)<cr> | |
" 字体配置 | |
exec 'set guifont='.iconv('Courier_New', &enc, 'gbk').':h10:cANSI' | |
exec 'set guifontwide='.iconv('微软雅黑', &enc, 'gbk').':h10' | |
endif | |
if has("unix") && !has('gui_macvim') | |
set guifont=Consolas\ 9 | |
set guifontwide=Consolas\ 9 | |
set guifont=Courier\ 9\ Pitch\ 10 | |
endif | |
if has("mac") || has("gui_macvim") | |
if has("gui_macvim") | |
" MacVim 下的字体配置 | |
set guifont=Consolas:h12 | |
set guifontwide=Consolas:h12 | |
" 使用 MacVim 原生的全屏幕功能 | |
let s:lines=&lines | |
let s:columns=&columns | |
func! FullScreenEnter() | |
set lines=999 columns=999 | |
set fu | |
endf | |
func! FullScreenLeave() | |
let &lines=s:lines | |
let &columns=s:columns | |
set nofu | |
endf | |
func! FullScreenToggle() | |
if &fullscreen | |
call FullScreenLeave() | |
else | |
call FullScreenEnter() | |
endif | |
endf | |
" 按 \ff 切换全屏 | |
map <Leader>ff :call FullScreenToggle()<cr> | |
" Set input method off | |
set imdisable | |
" 如果为空文件,则自动设置当前目录为桌面 | |
lcd ~/Desktop/ | |
" 自动切换到文件当前目录 | |
set autochdir | |
endif | |
endif | |
endif | |
" ========= | |
" 快捷键 | |
" ========= | |
" 标签相关的快捷键 | |
nmap <C-t> :tabnew<cr> | |
nmap <C-p> :tabprevious<cr> | |
nmap <C-n> :tabnext<cr> | |
nmap <C-k> :tabclose<cr> | |
nmap <C-Tab> :tabnext<cr> | |
"for i in range(1, &tabpagemax) | |
" exec 'nmap <A-'.i.'> '.i.'gt' | |
"endfor | |
nmap <LEFT> :bprevious<cr> | |
nmap <RIGHT> :bnext<cr> | |
" 插件快捷键 | |
nmap <C-d> :NERDTreeToggle<cr> | |
" 直接看代码 | |
nmap <C-c><C-f> :call GotoFirstEffectiveLine()<cr> | |
" Visual 中用 tab 和 shif-tab 做缩排 | |
vmap <Tab> :><CR>gv | |
vmap <S-Tab> :<<CR>gv | |
" ========= | |
" 插件 | |
" ========= | |
" VIM HTML 插件 | |
let g:no_html_toolbar = 'yes' | |
" The NERD tree | |
" http://www.vim.org/scripts/script.php?script_id=1658 | |
" taglist.vim | |
" http://www.vim.org/scripts/script.php?script_id=273 | |
" Color Sampler Pack | |
" http://www.vim.org/scripts/script.php?script_id=625 | |
" SuperTab continued. | |
" http://www.vim.org/scripts/script.php?script_id=1643 | |
" snipMate | |
" http://www.vim.org/scripts/script.php?script_id=2540 | |
" xptemplate | |
" http://www.vim.org/scripts/script.php?script_id=2611 | |
" snipMate 和 SuperTab 有冲突, xptemplate 试用中 | |
" matchit.zip | |
" http://www.vim.org/scripts/script.php?script_id=39 | |
" The NERD Commenter | |
" http://www.vim.org/scripts/script.php?script_id=1218 | |
" php.vim | |
" http://www.vim.org/scripts/script.php?script_id=1571 | |
" ZenCoding.vim | |
" http://www.vim.org/scripts/script.php?script_id=2981 | |
" DoxygenToolkit.vim | |
" http://www.vim.org/scripts/script.php?script_id=987 | |
" BlockComment.vim | |
" http://www.vim.org/scripts/script.php?script_id=473 | |
" vcscommand.vim : CVS/SVN/SVK/git/hg/bzr integration plugin | |
" http://www.vim.org/scripts/script.php?script_id=90 | |
" vim: set et sw=4 ts=4 sts=4 fdm=marker ft=vim ff=unix fenc=utf8: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment