Skip to content

Instantly share code, notes, and snippets.

@isS
Created September 1, 2012 18:05
Show Gist options
  • Save isS/3581931 to your computer and use it in GitHub Desktop.
Save isS/3581931 to your computer and use it in GitHub Desktop.
.vimrc MacVim配置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 文件编码选项
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set fileencoding=chinese
set fileencodings=ucs-bom,utf-8,chinese,gb18030,gbk,gb2312,cp936,prc,taiwan,latin-1
"set fileencoding=utf-8
set encoding=utf8
set ffs=unix,dos,mac "设置换行符格式
set ff=unix "设置缓冲区换行符格式
set nobomb "BOM(字节顺序标记)
"中文提示信息
"set langmenu=none
"set encod=utf-8
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 常规选项
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible "兼容VI模式
set history=300 "设置记录历史命令选项
set autoread "自动载入,用于不同编辑器处理同一文件时.
set mouse=a "启用鼠标选项,a为所有模式启用鼠标
set nu "开启行号
set helplang=cn "设置帮助为中文
set guioptions-=T "隐藏工具栏
set transparency=5 "透明背景70%
"set gui options
if has("gui_running")
"set guifont=Andale\ Mono:h12
set guifont=Monaco:h12
" exec 'set guifontwide='.iconv('宋体', &enc, 'gbk').':h10'
"set guifontwide=NSimsun:h9:cGB2312
"set guifontwide=Mircsoft\ YaHei:h10:cGB2312
endif
".vimrc编辑后自动生效,避免重启
autocmd! bufwritepost .vimrc source ~/.vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 编辑选项
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 制表符
set tabstop=4
set expandtab
set smarttab
set shiftwidth=4
set softtabstop=4
"Indententation
set noexpandtab
set copyindent
"set formatoptions=tcoqmM
set ts=4 sw=4 noet
" 代码折叠
set foldmethod=marker
" 状态栏显示目前所执行的指令
set showcmd
" 插入模式下使用 <BS>、<Del> <C-W> <C-U>
set backspace=indent,eol,start
set ruler
" show matching bracets
set showmatch
""""""""""""""""""""""""""""""
" => 语法选项
""""""""""""""""""""""""""""""
filetype plugin on "开启支持文件类型的插件
filetype indent on "开启支持文件类型的缩进
" 缩进
set autoindent
set smartindent
set cindent
"open syntax highlight
syntax on
syntax enable
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 文件备份选项
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nobackup "关闭备份turn backup off
set nowb
set noswapfile
""""""""""""""""""""""""""""""
" => 状态栏
""""""""""""""""""""""""""""""
"Always hide the statusline
set laststatus=2
"黓认状态栏格式
"hi StatusLine guifg=#FFFFFF guibg=#393939 gui=none
"if version >= 700
autocmd InsertEnter * hi StatusLine guifg=#393939 guibg=Grey gui=none
" autocmd InsertLeave * hi StatusLine guifg=#FFFFFF guibg=#393939 gui=none
" endif
" 命令行于状态行
set cmdheight=1 " 设置命令行的高度
set laststatus=2 " 始终显示状态行
set stl=\ [File]\ %F%m%r%h%y[%{&fileformat},%{&fileencoding}]\ %w\ \ [PWD]\ %r%{GetPWD()}%h\ %=\ [Line]%l/%L\ %=\[%P] "设置状态栏的信息
set statusline=\ %{HasPaste()}%<%-15.25(%f%)%m%r%h\ %w\ \
set statusline+=\ \ \ [%{&ff}/%Y]
set statusline+=\ \ \ %<%20.30(%{hostname()}:%{CurDir()}%)\
set statusline+=%=%-10.(%l,%c%V%)\ %p%%/%L
set columns=160
set lines=50
set tw=80 " textwidth,设置文本行宽度
"set fo+=Mm " formatoptions,设置自动换行的条件
function! CurDir()
let curdir = substitute(getcwd(), $HOME, "~", "")
return curdir
endfunction
function! HasPaste()
if &paste
return '[PASTE]'
else
return ''
endif
endfunction
" Basic editing options
set expandtab
au FileType html,python,vim,javascript setl shiftwidth=2
au FileType html,python,vim,javascript setl tabstop=2
au FileType java,php setl shiftwidth=4
au FileType java,php setl tabstop=4
set smarttab
" C-style indeting
set cindent
set nowrap " Wrap lines
set hlsearch
"colorscheme murphy
set background=dark
colorscheme molokai
"colorscheme solarized
"colorscheme darkeclipse
"let g:molokai_original = 1
" Do not redraw, when running macros.. lazyredraw
set lz
" set 7 lines to the curors - when moving vertical..
set so=7
" The commandbar is 2 high
set cmdheight=2
" Change buffer - without saving
set hid
" Set magic on
set magic
" No sound on errors.
set noerrorbells
set novisualbell
set hlsearch " Highlight search things
set imdisable
" Search options
set incsearch
set ignorecase
set smartcase "if mixed characters, perform case sensitive
"set cursorline
set hlsearch
set gdefault "substitute all, /g, flag by default is on. /g - now does single substitutions
set wrap
set linebreak
" Fancy UI options
"Status line
set statusline=%F " File name (tail) of file in the buffer.
set statusline+=%m " Modified flag, text is "[+]"; "[-]" if 'modifiable' is off.
set statusline+=%r " Readonly flag, text is "[RO]".
set statusline+=\ [T=%Y " Type of file in the buffer, e.g., ",VIM".
set statusline+=\ EOL=%{&ff} " Type of end-of-line,e.g. "dos" or "unix"
set statusline+=\ ENC=%{&fenc}] " Encoding, e.g. "utf-8"
set statusline+=[chr=\%03.3b/0x\%02.2B] " Value of byte under cursor (b), and in hex (B)
set statusline+=\ %=[%c:%l " Column number and line number
set statusline+=\ (%p%%\ of\ %L)] " Percentage through file in lines (p) and number of lines in buffer (L)
"set statusline+=cterm=bold
"set statusline+=ctermfg=yellow
set laststatus=2
"se:if expand("%") == ""|browse confirm w|else|confirm w|endif
set nolist
" Under the Mac(MacVim)
if has("gui_macvim")
" Mac 下,按 \ff 切换全屏
map <Leader>ff :call FullScreenToggle()<cr>
" I like TCSH :^)
set shell=/bin/tcsh
" Set input method off
set imdisable
" Set QuickTemplatePath
let g:QuickTemplatePath = $HOME.'/.vim/templates/'
" 如果为空文件,则自动设置当前目录为桌面
lcd ~/Desktop/
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
nmap <leader>w :w!<cr>
"" 括号自动补全
function! AutoClose()
:inoremap ( ()<ESC>i
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
:inoremap ` ``<ESC>i
:inoremap { {}<ESC>i
:inoremap [ []<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap ] <c-r>=ClosePair(']')<CR>
endf
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
"auto close for PHP and Javascript script
au FileType css,html,php,c,python,javascript exe AutoClose()
" Auto Check Syntax
""au BufWritePost,FileWritePost *.js,*.php call CheckSyntax(1)
" JavaScript 语法高亮
au FileType html,javascript let g:javascript_enable_domhtmlcss = 1
au BufRead,BufNewFile *.js setf jquery
au BufRead,BufNewFile *.php set filetype=php.html.css.javascript "将.php文件的类型同时设为php和html
au BufRead,BufNewFile *.html set filetype=html.css.javascript "将.html, .htm文件的类型同时设为css和html.javascript
au BufRead,BufNewFile *.htm set filetype=html.css.javascript "将.html, .htm文件的类型同时设为css和html.javascript
" 格式化 JavaScript 文件
nmap <silent> <leader>js :call g:Jsbeautify()<cr>
"au FileType javascript map <f12> :call g:Jsbeautify()<cr>
au FileType javascript set omnifunc=javascriptcomplete#CompleteJS
" 增加 ActionScript 语法支持
au BufNewFile,BufRead,BufEnter,WinEnter,FileType *.as setf actionscript
" CSS3 语法支持
au BufRead,BufNewFile *.css set ft=css syntax=css3
" 增加 Objective-C 语法支持
au BufNewFile,BufRead,BufEnter,WinEnter,FileType *.m,*.h setf objc
" 将指定文件的换行符转换成 UNIX 格式
au FileType php,javascript,html,css,python,vim,vimwiki set ff=unix
" 打开javascript折叠
let b:javascript_fold=1
" 打开javascript对dom、html和css的支持
let javascript_enable_domhtmlcss=1
autocmd FileType php set omnifunc=phpcomplete
"autocmd FileType html,php set omnifunc=htmlcomplete
" 使用(CTRL-L)命令来检查PHP语法 autocmd FileType php noremap <C-K> :!/Application/XAMPP/xamppfiles/bin/php -l %<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree {{{
nmap <leader>t :NERDTreeToggle<CR>
" store the bookmarks file
" let NERDTreeBookmarksFile=expand("$HOME/.vim/.tmp/NERDTreeBookmarks")
" show hidden files, too
let NERDTreeShowHidden=1
let NERDTreeShowFiles=1
" highlight the selected entry in the tree
let NERDTreeHighlightCursorline=1
" use a single click to fold/unfold directories and a double click to open files
let NERDTreeMouseMode=1
" automatically CWD to root node
let NERDTreeChDirMode=2
" close NERDTree after file is opened
let NERDTreeQuitOnOpen=1
" don't display these kinds of files
let NERDTreeIgnore=[ '^\.git$','^\.svn$','^\.DS_Store$','^\.[\w\.]+\.swp$','\.pyc$', '\.pyo$', '\.py\$class$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$' ]
" Show the bookmarks table on startup
let NERDTreeShowBookmarks=1
" Highlight the selected entry in the tree
let NERDTreeHighlightCursorline=1
"NERD_commenter
let NERDShutUp=1
""}}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Javascript
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"设置JS字典
autocmd FileType javascript set dictionary+=~/.vim/dict/javascript.dict
autocmd FileType javascript set dictionary+=~/.vim/dict/js-jquery.dict
" 打开javascript折叠
let b:javascript_fold=1
" 打开javascript对dom、html和css的支持
let javascript_enable_domhtmlcss=1
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Php
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"设置php字典
autocmd FileType php set dictionary+=~/.vim/dict/PHP.dict
au FileType php setlocal dictionary+=~/.vim/dict/php_function_list.txt
""autocmd FileType php set dictionary+=$VIMRUNTIME/dict/PHP.dict
autocmd FileType htm html set dictionary+=$VIMRUNTIME/dict/html.dict
"autocmd FileType css html htm set dictionary+=~/.vim/dict/css.dict
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" =>SQL自动补全
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:sql_type_default = 'mysql'
"autocmd FileType sql php set dictionary+=~/.vim/dict/sql.dict
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 模板选项
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
source ~/.vim/plugin/Template.vim
map nh :NewTemplateTab xhtml<cr>
map nh5 :NewTemplateTab html5<cr>
map np :NewTemplateTab php<cr>
map nj :NewTemplateTab javascript<cr>
map nc :NewTemplateTab css<cr>
"source ~/.vim/plugin/word_complete.vim
""""""""""""""""""""""""""""""""""""""""""
"=>Plugin configuration
""""""""""""""""""""""""""""""""""""""""""
" TagList settings {{{
autocmd VimEnter * TlistToggle "启动时强制打开taglist窗口
nmap <leader>l :TlistClose<CR>:TlistToggle<CR>
nmap <leader>L :TlistClose<CR>
" quit Vim when the TagList window is the last open window
let Tlist_Exit_OnlyWindow=1 " quit when TagList is the last open window
let Tlist_GainFocus_On_ToggleOpen=1 " put focus on the TagList window when it opens
"let Tlist_Process_File_Always=1 " process files in the background, even when the TagList window isn't open
let Tlist_WinWidth=40 " set the width
let Tlist_Inc_Winwidth=1 " increase window by 1 when growing
let Tlist_Ctags_Cmd = "/usr/local/bin/ctags"
" show function/method prototypes in the list
let Tlist_Display_Prototype=1
" don't show scope info
let Tlist_Display_Tag_Scope=0
" show TagList window on the right
let Tlist_Use_Right_Window=1
let Tlist_Show_One_File = 1
let Tlist_Auto_Highligt_Tag=1
let Tlist_Auto_Open = 1
let Tlist_Auto_Update = 1
let Tlist_Close_On_Select = 0
let Tlist_Compact_Format = 0
let Tlist_Enable_Fold_Column = 0
let Tlist_Exit_OnlyWindow = 0
let TList_GainFocus_On_ToggleOpen = 1 "打开时焦点不放在tl窗口中
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Hightlight_Tag_On_BufEnter = 1
let Tlist_Max_Submenu_Items = 1
let Tlist_Max_Tag_Length = 30
let Tlist_Process_File_Always = 0
let Tlist_Show_Menu = 0
let Tlist_Sort_Type = "order"
let Tlist_Use_Horiz_Window = 0
let tlist_php_settings = 'php;c:class;i:interfaces;d:constant;f:function'
au BufRead,BufNewFile *.js set ft=javascript.jquery
"}}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Omni complete functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
":if expand("%") == ""|browse confirm w|else|confirm w|endif
"autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascrīpt set omnifunc=javascrīptcomplete#CompleteJS
autocmd FileType html php 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
" Enable omni completion.
" use syntax complete if nothing else available
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
endif
source ~/.vim/php-doc.vim
inoremap <C-L> <ESC>:call PhpDocSingle()<CR>i
nnoremap <C-L> :call PhpDocSingle()<CR>
vnoremap <C-L> :call PhpDocRange()<CR>
let g:tbcompressor_command = 'compressor.cmd'
source ~/.vim/autoload/pathogen.vim
source ~/.vim/plugin/zencoding.vim
let g:user_zen_expandabbr_key = '<c-e>'
let g:use_zen_complete_tag = 1
"minibuf
let g:miniBufExplMapWindowNavVim = 1 "<C-jklh>切换
let g:miniBufExplMapCTabSwitchBufs = 1 "<C-Tab>切换窗口
let g:miniBufExplModSelTarget = 1
"缩进线: if expand("%") == ""|browse confirm w|else|confirm w|endif
"style 1
""syn match 4spa /\(\s\{4}\|\n\)\&\%1v.*\%2v/
""syn match 8spa /\s\{4}\&\%5v.*\%6v/
""syn match 12spa /\s\{4}\&\%9v.*\%10v/
""syn match 16spa /\s\{4}\&\%13v.*\%14v/
""syn match 20spa /\s\{4}\&\%17v.*\%18v/
""syn match 24spa /\s\{4}\&\%21v.*\%22v/
"style 2
syn match 4spa /\(\s\|\n\)\&\%4v.*\%5v/
syn match 8spa /\s\&\%8v.*\%9v/
syn match 12spa /\s\&\%12v.*\%13v/
syn match 16spa /\s\&\%16v.*\%17v/
syn match 20spa /\s\&\%20v.*\%21v/
syn match 24spa /\s\&\%24v.*\%25v/
syn match 80spa /.\&\%80v.*\%81v/
"indent color
hi 4spa guibg = #771144
hi 8spa guibg = #22464A
hi 12spa guibg = #344333
hi 16spa guibg = #777444
hi 20spa guibg = #555777
hi 24spa guibg = #cc9966
hi 80spa guibg = #ff1111
"缩进设置
set nolist
"hi SpecialKey guifg=#666666
"set cursorcolumn " 高亮光标列
"set cursorline " 高亮光标行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment