Created
July 2, 2014 06:27
-
-
Save jouyouyun/7f6e9c879d221e8373af to your computer and use it in GitHub Desktop.
vimrc
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
" 关闭兼容模式 | |
set nocompatible | |
filetype off " required | |
set rtp+=~/.vim/bundle/vundle/ | |
call vundle#begin() | |
"let Vundle manager Vundle | |
"required! | |
Bundle 'gmarik/vundle' | |
"Bundle 'https://github.com/mileszs/ack.vim.git' | |
Bundle 'rking/ag.vim' | |
Bundle 'https://github.com/vim-scripts/IndentAnything.git' | |
Bundle 'https://github.com/scrooloose/nerdcommenter.git' | |
Bundle 'https://github.com/vim-scripts/Tagbar.git' | |
Bundle 'https://github.com/vim-scripts/rainbow_parentheses.vim.git' | |
Bundle 'https://github.com/kchmck/vim-coffee-script.git' | |
Bundle 'https://github.com/jnwhiteh/vim-golang.git' | |
Bundle 'https://github.com/jcf/vim-latex.git' | |
Bundle 'https://github.com/plasticboy/vim-markdown.git' | |
Bundle 'https://github.com/peterhoeg/vim-qml.git' | |
filetype plugin indent on " required! | |
" | |
"Brief help | |
"BundleList - list configured bundles | |
" :BundleInstall(!) - install (update) bundles | |
" :BundleSearch(!) foo - search (or refresh cache first) for foo | |
" :BundleClean(!) - confirm (or auto-approve) removal of unused bundles | |
" | |
" see :h vundle for more details or wiki for FAQ | |
" NOTE: comments after Bundle commands are not allowed | |
"定义快捷键的前缀,即<Leader> | |
let mapleader=";" | |
" 行首、行尾与文件开头、文件结尾 | |
nmap <Leader>lb 0 | |
nmap <Leader>le $ | |
nmap <Leader>fb gg | |
nmap <Leader>fe G | |
" 设置快捷键将选中文本块复制至系统剪贴板 | |
vnoremap <Leader>y "+y | |
nmap <Leader>y "+yy | |
" 设置快捷键将系统剪贴板内容粘贴至 vim | |
nmap <Leader>p "+p | |
" 定义快捷键关闭当前分割窗口 | |
nmap <Leader>q :q<CR> | |
" 定义快捷键保存当前窗口内容 | |
nmap <Leader>w :w<CR> | |
" 定义快捷键保存所有窗口内容并退出 vim | |
nmap <Leader>WQ :wa<CR>:q<CR> | |
" 不做任何保存,直接退出 vim | |
nmap <Leader>Q :qa!<CR> | |
" 依次遍历子窗口 | |
nnoremap <Leader>nw <C-W><C-W> | |
" 跳转至右方的窗口 | |
nnoremap <Leader>lw <C-W>l | |
" 跳转至方的窗口 | |
nnoremap <Leader>hw <C-W>h | |
" 跳转至上方的子窗口 | |
nnoremap <Leader>kw <C-W>k | |
" 跳转至下方的子窗口 | |
nnoremap <Leader>jw <C-W>j | |
" 定义快捷键在结对符之间跳转,助记 pair | |
nmap <Leader>pa % | |
" 开启实时搜索功能 | |
set incsearch | |
" 搜索时大小写不敏感 | |
set ignorecase | |
" vim 自身命令行模式智能补全 | |
set wildmenu | |
" 颜色主题设置 | |
set t_Co=256 | |
"colorscheme molokai | |
if &t_Co > 2 || has("gui_running") | |
syntax enable | |
set hlsearch | |
set t_Co=256 " to use molokai in terminal | |
if &term != "linux" && findfile("molokai.vim", finddir("~/.vim/bundle/molokai/colors")) != "" | |
colorscheme molokai | |
if !has("gui_running") | |
hi Normal ctermbg=none | |
hi LineNr ctermbg=none | |
hi NonText ctermbg=none | |
hi Comment ctermfg=228 | |
endif | |
hi ColorColumn ctermbg=238 guibg=darkgray | |
else | |
colorscheme desert | |
endif | |
endif | |
"colorscheme obsidian | |
" 开启语法高亮功能 | |
syntax enable | |
" 允许用指定语法高亮配色方案替换默认方案 | |
syntax on | |
" 根据侦测到的不同类型加载对应的插件 | |
"filetype plugin on | |
" 开启文件类型侦测 | |
filetype on | |
" 禁止光标闪烁 | |
"set gcr=a:block-blinkon0 | |
" 禁止显示滚动条 | |
"set guioptions-=l | |
"set guioptions-=L | |
"set guioptions-=r | |
"set guioptions-=R | |
" 禁止显示菜单和工具条 | |
"set guioptions-=m | |
"set guioptions-=T | |
" 总是显示状态栏 | |
set laststatus=2 | |
" 显示光标当前位置 | |
set ruler | |
" 开启行号显示 | |
set number | |
" 高亮显示当前行/列 | |
set cursorline | |
set cursorcolumn | |
" 高亮显示搜索结果 | |
set hlsearch | |
" 禁止折行 | |
"set nowrap | |
set wrap | |
" tab -> | | |
set list lcs=tab:\|\ | |
" 设置状态栏主题风格 | |
set encoding=utf-8 | |
let g:Powerline_colorscheme='solarized256' | |
let g:Powerline_symbols = 'fancy' | |
" 自适应不同语言的智能缩进 | |
filetype indent on | |
" 设置编辑时制表符占用空格数 | |
set tabstop=8 | |
" 设置格式化时制表符占用空格数 | |
set shiftwidth=8 | |
" 让 vim 把连续数量的空格视为一个制表符 | |
set softtabstop=8 | |
"解决shiftwidth和tabstop不等时的麻烦 | |
set smarttab | |
" 将制表符扩展为空格 | |
"set expandtab | |
" 基于缩进或语法进行代码折叠 | |
" za,打开或关闭当前折叠;zM,关闭所有折叠;zR,打开所有折叠 | |
"set foldmethod=indent | |
set foldmethod=syntax | |
" 启动 vim 时关闭折叠代码 | |
set nofoldenable | |
" *.cpp 和 *.h 间切换 | |
nmap <Leader>ch :A<CR> | |
" 子窗口中显示 *.cpp 或 *.h 垂直分割 | |
nmap <Leader>vch :AV<CR> | |
" 水平分割 | |
nmap <Leader>sch :AS<CR> | |
"set omnifunc | |
set omnifunc=syntaxcomplete#Complete | |
autocmd FileType python set omnifunc=pythoncomplete#Complete | |
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS | |
autocmd FileType html 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 | |
autocmd FileType cpp set omnifunc=cppcomplete#Complete | |
" 设置 tagbar 子窗口的位置出现在主编辑区的左边 | |
let tagbar_left=1 | |
" 设置显示/隐藏标签列表子窗口的快捷键。速记:tag list | |
nnoremap <Leader>tl :TagbarToggle<CR> | |
" 设置标签子窗口的宽度 | |
let tagbar_width=32 | |
" tagbar 子窗口中不显示冗余帮助信息 | |
let g:tagbar_compact=1 | |
" 设置 ctags 对哪些代码元素生成标签 | |
let g:tagbar_type_cpp = { | |
\ 'kinds' : [ | |
\ 'd:macros:1', | |
\ 'g:enums', | |
\ 't:typedefs:0:0', | |
\ 'e:enumerators:0:0', | |
\ 'n:namespaces', | |
\ 'c:classes', | |
\ 's:structs', | |
\ 'u:unions', | |
\ 'f:functions', | |
\ 'm:members:0:0', | |
\ 'v:global:0:0', | |
\ 'x:external:0:0', | |
\ 'l:local:0:0' | |
\ ], | |
\ 'sro': '::', | |
\ 'kind2scope' : { | |
\ 'g' : 'enum', | |
\ 'n' : 'namespace', | |
\ 'c' : 'class', | |
\ 's' : 'struct', | |
\ 'u' : 'union', | |
\ }, | |
\ 'scope2kind' : { | |
\ 'enum': 'g', | |
\ 'namespace' : 'n', | |
\ 'class': 'c', | |
\ 'struct': 's', | |
\ 'union': 'u', | |
\ } | |
\ } | |
let g:tagbar_type_asciidoc = { | |
\ 'ctagstype' : 'asciidoc', | |
\ 'kinds' : [ | |
\ 's:Table of Contents' | |
\ ] | |
\ } | |
let g:tagbar_type_go = { | |
\ 'ctagstype' : 'go', | |
\ 'kinds' : [ | |
\ 'p:package', | |
\ 'i:imports:1', | |
\ 'c:constants', | |
\ 'v:variables', | |
\ 't:types', | |
\ 'n:interfaces', | |
\ 'w:fields', | |
\ 'e:embedded', | |
\ 'm:methods', | |
\ 'r:constructor', | |
\ 'f:functions' | |
\ ], | |
\ 'sro' : '.', | |
\ 'kind2scope' : { | |
\ 't' : 'ctype', | |
\ 'n' : 'ntype' | |
\ }, | |
\ 'scope2kind' : { | |
\ 'ctype' : 't', | |
\ 'ntype' : 'n' | |
\ }, | |
\ 'ctagsbin' : 'gotags', | |
\ 'ctagsargs' : '-sort -silent' | |
\ } | |
" 启用:Man 命令查看各类 man 信息 | |
source $VIMRUNTIME/ftplugin/man.vim | |
" 定义:Man 命令查看各类 man 信息的快捷键 | |
nmap <Leader>man :Man 3 <cword><CR> | |
" 使用 NERDTree 插件查看工程文件。设置快捷键,速记:file list | |
" 回车,打开选中文件; | |
" r,刷新工程目录文件列表; | |
" I(大写),显示/隐藏隐藏文件; | |
" m,出现创建/删除/剪切/拷贝操作列表 | |
nmap <Leader>fl :NERDTreeToggle<CR> | |
" 设置 NERDTree 子窗口宽度 | |
let NERDTreeWinSize=32 | |
" 设置 NERDTree 子窗口位置 | |
let NERDTreeWinPos="right" | |
" 显示隐藏文件 | |
let NERDTreeShowHidden=1 | |
" NERDTree 子窗口中不显示冗余帮助信息 | |
let NERDTreeMinimalUI=1 | |
" 删除文件时自动删除文件对应 buffer | |
let NERDTreeAutoDeleteBuffer=1 | |
set tags+=$HOME/Public/vim-dict/sys.tags | |
"enable BackSpace | |
set backspace=indent,eol,start | |
"auto chdir | |
set autochdir | |
"补全列表颜色 | |
hi Visual ctermfg=darkblue ctermbg=white | |
hi PmenuSel ctermfg=white ctermbg=darkblue | |
hi Pmenu ctermfg=blue ctermbg=white | |
hi PmenuSbar ctermbg=5 | |
hi PmenuThumb ctermfg=yellow | |
hi CursorLine ctermbg=black | |
hi CursorColumn ctermbg=black | |
hi TabLine cterm=none ctermfg=0 ctermbg=7 | |
" 自动补齐括号书名号引号等设置 | |
"inoremap ( ()<LEFT> | |
"inoremap [ []<LEFT> | |
"inoremap { {}<LEFT> | |
inoremap ' ''<LEFT> | |
"inoremap " ""<LEFT> | |
inoremap ( ()<ESC>i | |
":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> | |
function ClosePair(char) | |
if getline('.')[col('.') - 1] == a:char | |
return "\<Right>" | |
else | |
return a:char | |
endif | |
endfunc | |
"括号高亮 RainbowParentheses 插件 | |
au VimEnter * RainbowParenthesesToggle | |
au Syntax * RainbowParenthesesLoadRound | |
au Syntax * RainbowParenthesesLoadSquare | |
au Syntax * RainbowParenthesesLoadBraces | |
"定义源代码格式化 | |
"map ,fc <Esc>:%!astyle --style=kr --indent=tab --indent-switches --indent-cases <CR> | |
"调用AStyle程序,进行代码美化 | |
func CodeFormat() | |
"取得当前光标所在行号 | |
let lineNum = line(".") | |
if &filetype == 'c' | |
"exec "%! astyle -A3Lfpjk3NS" | |
exec "%! astyle --style=kr --indent=tab" | |
elseif &filetype == 'cpp' | |
"exec "%! astyle -A3Lfpjk3NS" | |
exec "%! astyle --style=kr --indent=tab" | |
elseif &filetype == 'java' | |
exec "%! astyle -A2Lfpjk3NS" | |
else | |
echo "Not Support".&filetype." FileType" | |
endif | |
exec lineNum | |
endfunc | |
"映射代码美化函数到Shift+f快捷键 | |
map <S-F> <Esc>:call CodeFormat()<CR> | |
"autocmd! bufwritepost *.c :call CodeFormat() | |
"autocmd! bufwritepost *.cpp :call CodeFormat() | |
"进行版权声明的设置 | |
let g:vimrc_author='jouyouyun' | |
let g:vimrc_email='[email protected]' | |
let g:vimrc_homepage='http://jouyouyun.is-programmer.com' | |
"Deepin Template | |
autocmd BufNewFile *.c 0r ~/.vim/template/C.c | |
autocmd BufNewFile *.h 0r ~/.vim/template/H.h | |
autocmd BufNewFile *.go 0r ~/.vim/template/go.go | |
autocmd BufNewFile *.py 0r ~/.vim/template/PY.py | |
autocmd BufNewFile *.sh 0r ~/.vim/template/shell.sh | |
autocmd BufNewFile *.cpp 0r ~/.vim/template/CPP.cpp | |
autocmd BufNewFile *.coffee 0r ~/.vim/template/coffee.coffee | |
"Markdown | |
let g:vim_markdown_folding_disabled=1 | |
let g:vim_markdown_initial_foldlevel=1 | |
autocmd BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} map <Leader>mp :!"/usr/bin/google-chrome" %<CR> | |
" silver search ag | |
"let g:agprg="ag --nogroup --nocolor --column" | |
let g:agprg="ag --column" | |
nmap <F3> :Ag "<cword>"<CR> | |
set fileencoding=utf-8 | |
set fileencodings=utf-8,gb2312,gb18030,default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment