iuunhao
12/28/2015 - 3:37 PM

vim:vimrc


"基本设置
let mapleader = " "
let g:mapleader = " "

"避免乱码
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

" 设置当文件被改动时自动载入
set autoread

" vimrc文件修改之后自动加载
autocmd! bufwritepost .vimrc source %

"从不备份
set nobackup

set magic                   " 设置魔术
set guioptions-=T           " 隐藏工具栏
set guioptions-=m           " 隐藏菜单栏
set foldcolumn=0
set foldmethod=indent
set foldlevel=3


autocmd FileType apache setlocal commentstring=#\ %s
set nofoldenable

" 去掉输入错误的提示声音
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 在行和段开始处使用制表符
set smarttab
" 历史记录数
set history=1000
"禁止生成临时文件
set nobackup
set noswapfile
"搜索忽略大小写
set ignorecase
"搜索逐字符高亮
set hlsearch
set incsearch
"行内替换
set gdefault
"恢复光标关闭前位置
if has("autocmd")
    au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
" 总是显示状态行
set laststatus=2
" 侦测文件类型
filetype on

" 为特定文件类型载入相关缩进文件
filetype indent on
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 字符间插入的像素行数目
set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3

function! ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endfunction
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu
map <silent> <leader><cr> :noh<cr>


" 映射全选+复制 ctrl+a
map <C-A> ggVGY
map! <C-A> <Esc>ggVGY
map <F12> gg=G
" 选中状态下 Ctrl+c 复制
vmap <C-c> "+y
"去空行
nnoremap <F2> :g/^\s*$/d<CR>
"比较文件
nnoremap <C-F2> :vert diffsplit
" 设置当文件被改动时自动载入
set autoread
"共享剪贴板
set clipboard+=unnamed

" 历史记录数
set history=1000
"搜索忽略大小写
set ignorecase
"搜索逐字符高亮
set hlsearch
set incsearch
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" vimrc文件修改之后自动加载
autocmd! bufwritepost .vimrc source %
set foldmethod=indent

" 高亮搜索命中的文本
set hlsearch

" 随着键入即时搜索
set incsearch
" 搜索时忽略大小写
set ignorecase
" 显示括号配对情况
set showmatch
" 退格键可用
set backspace=2
" 缩进
set autoindent
set smartindent
" 保存文件时自动删除行尾空格或Tab
autocmd BufWritePre * :%s/\s\+$//e
autocmd BufWritePre * :%s/\s\+$//e
" 填充Tab
set expandtab
set tabstop=4
set shiftwidth=4
set shiftround


"显示相关
syntax enable           " 语法高亮
set nu              " 显示行号
set go=             " 不要图形按钮
autocmd InsertLeave * se nocul  " 用浅色高亮当前行
autocmd InsertEnter * se cul    " 用浅色高亮当前行
set nocompatible  "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限

" 设置配色方案
if has("gui_running")
    set background=dark
    "colorscheme peaksea
    "colorscheme Tomorrow-Night-Bright
    "colorscheme gruvbox
    "colorscheme onedark
    colorscheme solarized
endif


"字体
if has("mac") || has("macunix")
    "set gfn=Sauce\ Code\ Powerline\:h16
    "set gfn=Anonymice\ Powerline\:h16
    "set guifont=Source_Code_Pro:h18
    "set guifont=Inconsolata\ XL:h17,Inconsolata:h20,Monaco:h17
    set guifont=PragmataPro:h17
elseif has("win16") || has("win32")
    set gfn=Hack:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11
elseif has("linux")
    set gfn=Hack:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11
elseif has("unix")
    set gfn=Monospace\ 17
endif


"通用快捷键设置
noremap <silent> <C-left> :bprev<CR>
noremap <silent> <C-h> :bprev<CR>
noremap <silent> <C-right> :bnext<CR>
noremap <silent> <C-l> :bnext<CR>

nnoremap <Leader>h <C-w>h
nnoremap <Leader>l <C-w>l
nnoremap <Leader>j <C-w>j
nnoremap <Leader>k <C-w>k

map <C-A> <Esc>ggVG
noremap H ^
noremap L $
vnoremap L g_
map ,cd :cd %:p:h<CR>
nmap <silent> <Leader>ev :e $MYVIMRC<CR>
nmap <silent> <Leader>es :so $MYVIMRC<CR>
inoremap jj <ESC>
nmap j gj
nmap k gk
map <Leader>v "+gP
map <Leader>c "+y
nmap <leader>F :%s//g<LEFT><LEFT>

map <Leader>T :%s/\s\+$//<CR>
map <Leader>U :g/^$/d<CR>
map <Leader>R :retab<CR>
map <leader>cd :cd %:p:h<cr>:pwd<cr>

nnoremap <leader>\ :vs<CR>
nnoremap <leader>- :sp<CR>

nnoremap <leader>vi :BundleInstall<CR>

nnoremap ; :
"nnoremap : ;
noremap <silent> <Left> :bp<CR>
noremap <silent> <Right> :bn<CR>

nnoremap \ :!open <C-R>%<CR><CR>

xnoremap p pgvy

"插件列表


set nocompatible               " be iMproved
filetype off                   " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'

"------------------
" Code Completions
"------------------
Bundle 'Shougo/neocomplcache'
Bundle 'mattn/emmet-vim'
Bundle 'Raimondi/delimitMate'
Bundle 'ervandew/supertab'
Bundle 'vim-scripts/mru.vim'
"-----------------
" Fast navigation
"-----------------
Bundle 'edsono/vim-matchit'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'tpope/vim-commentary'

"--------------
" Fast editing
"--------------
Bundle 'tpope/vim-surround'
Bundle 'scrooloose/nerdcommenter'
"Bundle 'nathanaelkane/vim-indent-guides'

"--------------
" IDE features
"--------------
Bundle 'scrooloose/nerdtree'
"Bundle 'humiaozuzu/TabBar'
"Bundle 'mileszs/ack.vim'
Bundle 'kien/ctrlp.vim'
"Bundle 'tpope/vim-fugitive'
Bundle 'bling/vim-airline'
Bundle 'vim-airline/vim-airline-themes'
Bundle 'mattn/webapi-vim'
Bundle 'scrooloose/syntastic'

"----------------------------------------
" Syntax/Indent for language enhancement
"----------------------------------------
"------- web backend ---------
"Bundle '2072/PHP-Indenting-for-VIm'
Bundle 'digitaltoad/vim-jade'

"------- web frontend ----------
Bundle 'othree/html5.vim'
Bundle 'pangloss/vim-javascript'
Bundle 'nono/jquery.vim'

"------- markup language -------
Bundle 'tpope/vim-markdown'
Bundle "ap/vim-css-color"
Bundle 'junegunn/goyo.vim'
Bundle 'vim-scripts/bufexplorer.zip'
Bundle 'terryma/vim-multiple-cursors'
"Bundle 'AtsushiM/sass-compile.vim'
Bundle 'vim-scripts/sessionman.vim'
Bundle 'flazz/vim-colorschemes'
"Bundle 'mbriggs/mark.vim'
"--------------
" Color Schemes
"--------------
"Bundle 'fisadev/fisa-vim-colorscheme'
Bundle 'altercation/vim-colors-solarized'
Bundle 'morhetz/gruvbox'
"Bundle 'joshdick/onedark.vim'
"Bundle 'joshdick/airline-onedark.vim'



Bundle 'shougo/vimshell.vim'
Bundle 'shougo/vimproc.vim'
Bundle 'vcscommand.vim'
Bundle 'mhinz/vim-startify'
Bundle 'majutsushi/tagbar'
Bundle 'nathanaelkane/vim-indent-guides'


Bundle 'mattn/gist-vim'
Bundle 'airblade/vim-gitgutter'
Bundle 'jelera/vim-javascript-syntax'

Bundle 'sjl/gundo.vim'

Bundle 'jiangmiao/auto-pairs'
let g:AutoPairsFlyMode = 0
let g:AutoPairsShortcutBackInsert = '<M-b>'

Bundle 'juneedahamed/svnj.vim'
Bundle 'yonchu/accelerated-smooth-scroll'
Bundle 'msanders/snipmate.vim'


filetype plugin indent on     " required!


"插件配置
" F4显示TagList
nmap <silent> <F4> :TagbarToggle<CR>


" easy-motion
let g:EasyMotion_leader_key = 'f'

" Nerd Tree
let NERDChristmasTree=0
let NERDTreeWinSize=30
let NERDTreeChDirMode=2
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
" let NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$',  '\~$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos = "left"
map <Leader>n :NERDTreeMirror<CR>
map <Leader>n :NERDTreeToggle<CR>

" nerdcommenter
let NERDSpaceDelims=1
let NERDCompactSexyComs=1

" ZenCoding
let g:user_emmet_expandabbr_key='<d-j>'

" NeoComplCache
let g:neocomplcache_enable_at_startup=1
let g:neoComplcache_disableautocomplete=1
"let g:neocomplcache_enable_underbar_completion = 1
"let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_smart_case=1
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
set completeopt-=preview

imap <C-k> <Plug>(neocomplcache_snippets_force_expand)
smap <C-k> <Plug>(neocomplcache_snippets_force_expand)
imap <C-l> <Plug>(neocomplcache_snippets_force_jump)
smap <C-l> <Plug>(neocomplcache_snippets_force_jump)

" SuperTab
" let g:SuperTabDefultCompletionType='context'
let g:SuperTabDefaultCompletionType = '<C-X><C-U>'
let g:SuperTabRetainCompletionType=2

" ctrlp
set wildignore+=*/tmp/*,*.so,*.o,*.a,*.obj,*.swp,*.zip,*.pyc,*.pyo,*.class,.DS_Store  " MacOSX/Linux
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'

" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
"map f /
map <c-space> ?

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Vimroom
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:goyo_width=100
let g:goyo_margin_top = 2
let g:goyo_margin_bottom = 2
nnoremap <silent> <leader>z :Goyo<cr>

""""""""""""""""""""""""""""""
" => MRU plugin
""""""""""""""""""""""""""""""
let MRU_Max_Entries = 600
map <leader>f :MRU<CR>

" Multi Expand Region
map K <Plug>(expand_region_expand)
map J <Plug>(expand_region_shrink)

"Session
set sessionoptions=blank,buffers,curdir,folds,tabpages,winsize
nmap <leader>sl :SessionList<CR>
nmap <leader>ss :SessionSave<CR>
nmap <leader>sc :SessionClose<CR>


""""""""""""""""""""""""""""""
" => bufExplorer plugin
""""""""""""""""""""""""""""""
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
let g:bufExplorerFindActive=1
let g:bufExplorerSortBy='name'
map <leader>o :BufExplorer<cr>

""""""""""""""""""""""""""""""
" => vim-gist
""""""""""""""""""""""""""""""
let g:gist_clip_command = 'pbcopy'


""""""""""""""""""""""""""""""
" => vim-airline
""""""""""""""""""""""""""""""
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
""""""""""""""""""""""""""""""
" => TagListe
""""""""""""""""""""""""""""""
nmap <leader>t :TagbarToggle<CR>

nmap <leader>g :GundoToggle <CR>
nmap <c-m> <c-u>

"自动进入打开文件所在目录
execute "cd" expand("%:h")



" 在浏览器预览 for Mac
function! ViewInBrowser(name)
    let file = expand("%:p")
    let l:browsers = {
                \"cr":"open -a \"Google Chrome\"",
                \"ff":"open -a Firefox",
                \}
    let htdocs='/Users/leon1/'
    let strpos = stridx(file, substitute(htdocs, '\\\\', '\', "g"))
    let file = '"'. file . '"'
    exec ":update " .file
    "echo file .' ## '. htdocs
    if strpos == -1
        exec ":silent ! ". l:browsers[a:name] ." file://". file
    else
        let file=substitute(file, htdocs, "http://127.0.0.1:8090/", "g")
        let file=substitute(file, '\\', '/', "g")
        exec ":silent ! ". l:browsers[a:name] file
    endif
endfunction
nmap <Leader>cr :call ViewInBrowser("cr")<cr>