1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 "" 使用办法 3 "" 1: git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle 4 "" 2: vim foo 5 "" 3: :BundleUpdate 6 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 7 "" 1: gui全屏的时候会有一点小问题 8 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 9 "" Date: 2014年 03月 17日 星期一 09:35:03 CST 10 "" Date: 2014 07 24 11 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 12 13 "设置为逗号比较好,因为不同的键盘\按键会有不一样的位置 14 let mapleader=',' 15 16 " 快速打开vimrc的配置文件 17 map ee :tabnew $HOME/.vimrc 18 19 " ^Z快速进入shell 20 nmap :shell 21 22 " 判断操作系统 23 if (has("win32") || has("win64") || has("win32unix")) 24 let g:isWin = 1 25 else 26 let g:isWin = 0 27 endif 28 29 " 判断是终端还是gvim 30 if has("gui_running") 31 let g:isGUI = 1 32 else 33 let g:isGUI = 0 34 endif 35 36 "设置行号 37 :set nu 38 "自动缩进 39 :set autoindent 40 41 "设置缩进为4个字符,默认为8个 42 set softtabstop=4 43 set shiftwidth=4 44 set smarttab 45 set expandtab 46 47 "增加自动补齐路径 48 set path=.,/usr/include,/usr/include/c++/4.4.4 49 "打开语法高亮 50 syntax on 51 syntax enable 52 "设置背景颜色 53 set background=dark 54 "深色主题 对保护视力有一定的帮助 55 colorscheme delek 56 colorscheme evening 57 " 设置注释为绿色 58 highlight Comment ctermfg=red guifg=green 59 " 设置自动补齐窗口配色 60 highlight Pmenu guibg=lightgrey ctermbg=lightgrey guifg=black ctermfg=black 61 highlight PmenuSel guibg=lightgrey ctermbg=blue guifg=blue ctermfg=red 62 63 " 右下角显示完整命令 64 set showcmd 65 66 " 打开智能识别 67 " 自动识别文件类型 68 " 用文件类型plugin脚本 69 " 使用缩进定义文件 70 filetype plugin indent on 71 "help new-omni-completion help compl-omni "help ft-c-omni 72 "有一点要注意一下, 切记, 关於omni的设定要写在 filetype plugin ... on, 的后面 73 "autocmd FileType * set omnifunc=syntaxcomplete#Complete 74 autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete 75 autocmd FileType python set omnifunc=pythoncomplete#Complete 76 autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS 77 autocmd FileType html set omnifunc=htmlcomplete#CompleteTags 78 autocmd FileType css set omnifunc=csscomplete#CompleteCSS 79 autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags 80 autocmd FileType java set omnifunc=javacomplete#Complete 81 82 "查看制表符 83 set list 84 set listchars=tab:>-,trail:- 85 86 "设置屏幕上下边界 87 set scrolloff=5 88 "set nowrap "用zl zh 移动 89 "set wrap "用gj gk 移动 90 91 " 让左右箭头可以智能的上下左右 92 set whichwrap=b,s,<,>,h,l 93 94 " ctags 索引文件 95 set tags+=/usr/include/tags 96 set tags+=/usr/include/c++/4.4.4/tags 97 " 增加自动补齐路径 98 set path=.,/usr/include,/usr/include/c++/4.4.4 99 100 set cindent "C/C++风格缩进101 102 set shortmess=atI "去掉欢迎界面103 set ignorecase "搜索时忽略大小写104 set showmatch "显示匹配的括号105 set lbr "在breakat字符处而不是最后一个字符处断行106 set history=400 "vim记住的历史操作的数量,默认的是20107 set autoread "当文件在外部被修改时,自动重新读取108 set mouse=n "在所有模式下都允许使用鼠标,还可以是n,v,i,c等109 110 "在gvim中高亮当前行111 if (g:isGUI)112 set cursorline113 colorscheme wombat114 hi cursorline guibg=#333333115 hi CursorColumn guibg=#333333116 "set guifont=Consolas\ 10117 "set guifontwide=Consolas\ 10118 set guifont=DejaVu\ Sans\ Mono\ 10119 set gfw=DejaVu\ Sans\ Mono\ 10120 " 不显示toolbar121 set guioptions-=T122 " 不显示菜单栏123 "set guioptions-=m124 endif125 126 " 设置字符集编码,默认使用utf8127 if (g:isWin)128 let &termencoding=&encoding " 通常win下的encoding为cp936129 set fileencodings=utf8,cp936,ucs-bom,latin1130 else131 set encoding=utf8132 set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1133 endif134 135 " 状态栏136 set laststatus=2 " 总是显示状态栏137 highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue138 " 获取当前路径,将$HOME转化为~139 function! CurDir()140 let curdir = substitute(getcwd(), $HOME, "~", "g")141 return curdir142 endfunction143 set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{ CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ asci144 145 " 第80列往后加下划线146 "au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)147 148 " 根据给定方向搜索当前光标下的单词,结合下面两个绑定使用149 function! VisualSearch(direction) range150 let l:saved_reg = @"151 execute "normal! vgvy"152 let l:pattern = escape(@", '\\/.*$^~[]')153 let l:pattern = substitute(l:pattern, "\n$", "", "")154 if a:direction == 'b'155 execute "normal ?" . l:pattern . " "156 else157 execute "normal /" . l:pattern . " "158 endif159 let @/ = l:pattern160 let @" = l:saved_reg161 endfunction162 "用 */# 向 前/后 搜索光标下的单词163 vnoremap * :call VisualSearch('f') 164 vnoremap # :call VisualSearch('b') 165 166 " 在文件名上按时,在新的tab中打开167 " map gf :tabnew 168 169 " 恢复上次文件打开位置170 set viminfo='10,\"100,:20,%,n~/.viminfo171 au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif172 173 "从系统剪切板中复制,剪切,粘贴174 "map "+y175 "map "+x176 "map "+p177 178 " 快捷输入179 " 自动完成括号和引号180 inoremap 1 () :let leavechar=")" i181 inoremap { { { } kA 182 183 184 185 "使用caps Lock代替ESC,如果是输入大量的大写时,可以先输入小写,然后选中用U改变 186 "在终端中输入187 "xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'188 189 "快速编译选项190 "map :w :!make 191 " 快速打开当前目录下的文件 快速打开指定目录下的文件192 map :Texplore 193 map :tabpre 194 map :tabnext 195 map :w :make :cw j196 "map :w :!make :cw j197 map :cclose 198 map :!make run 199 "map : !clear && ./%< 200 201 nnoremap @=((foldclosed(line('.'))<0)? 'zc':'zo') 202 set foldmethod=indent203 set foldmethod=syntax204 set nofoldenable205 inoremap :call FoldEnable() 206 map :call FoldEnable() 207 208 let g:s_foldenable=0209 function! FoldEnable()210 if exists("g:s_foldenable")211 unlet g:s_foldenable212 set nofoldenable213 else214 let g:s_foldenable=1215 set foldenable216 endif217 endfunction218 219 "设置行高亮220 set cursorline221 "hi cursorline guibg=Grey40 guifg=red term=BOLD222 223 "窗口之间的快速跳转224 noremap h225 noremap j226 noremap k227 noremap l228 229 " 更新ctags和cscope索引230 " href: http://www.vimer.cn/2009/10/把vim打造成一个真正的ide2.html231 " 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令232 map :call Do_CsTag() 233 function! Do_CsTag()234 let dir = getcwd()235 "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。236 if ( DeleteFile(dir, "tags") ) 237 return 238 endif239 if ( DeleteFile(dir, "cscope.files") ) 240 return 241 endif242 if ( DeleteFile(dir, "cscope.out") ) 243 return 244 endif245 246 if(executable('ctags'))247 silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."248 endif249 if(executable('cscope') && has("cscope"))250 if(g:isWin)251 silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"252 else253 silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files"254 endif255 silent! execute "!cscope -b"256 execute "normal :"257 if filereadable("cscope.out")258 execute "cs add cscope.out"259 endif260 endif261 " 刷新屏幕262 execute "redr!"263 endfunction264 265 function! DeleteFile(dir, filename)266 if filereadable(a:filename)267 if (g:isWin)268 let ret = delete(a:dir."\\".a:filename)269 else270 let ret = delete("./".a:filename)271 endif272 if (ret != 0)273 echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None274 return 1275 else276 return 0277 endif278 endif279 return 0280 endfunction281 282 " cscope 绑定283 if has("cscope")284 set csto=1285 set cst286 set nocsverb287 if filereadable("cscope.out")288 cs add cscope.out289 endif290 set csverb291 " s: C语言符号 g: 定义 d: 这个函数调用的函数 c: 调用这个函数的函数292 " t: 文本 e: egrep模式 f: 文件 i: include本文件的文件293 nmap ss :cs find s =expand(" ") 294 nmap sg :cs find g =expand(" ") 295 nmap sc :cs find c =expand(" ") 296 nmap st :cs find t =expand(" ") 297 nmap se :cs find e =expand(" ") 298 nmap sf :cs find f =expand(" ") 299 nmap si :cs find i ^ =expand(" ") $ 300 nmap sd :cs find d =expand(" ") 301 endif302 303 304 305 " 插件窗口的宽度,如TagList,NERD_tree等,自己设置306 let s:PlugWinSize = 20307 308 "下面是Vundle插件309 set rtp+=~/.vim/bundle/vundle310 call vundle#rc()311 312 "============================================================313 "vim分屏执行shell314 "使用的命令是 ConqueTermSplit , ConqueTermVSplit 315 Bundle 'vim-scripts/Conque-Shell'316 317 318 "============================================================319 "对不同的filetype进行注释320 "使用的方法是 gc{motion} , {visual}gc , gcu 撤销321 " \\{motion} , {visual}\\ 322 Bundle 'tpope/vim-commentary'323 324 325 "============================================================326 "类似vc中的workspace,列出文件中的所有宏,所有全局变量,函数名327 Bundle 'taglist.vim'328 "下面是配置329 let Tlist_Ctags_Cmd='/usr/bin/ctags -R'330 let Tlist_OnlyWindow=1331 let Tlist_Sort_Type='name'332 let Tlist_Auto_Open=1333 let Tlist_WinHeight=10334 "let Tlist_WinWidth=10335 let Tlist_Use_Horiz_Window=0336 let Tlist_Exit_OnlyWindow=1337 "使用TlistToggle命令打开338 339 340 "============================================================341 "Winanager 管理各个窗口342 "Bundle 'winmanager'343 ""下面是配置344 "let g:persistentBehaviour=0 "只剩下一个窗口时退出345 "let g:winManagerWidth=20346 "let g:defaultExplorer=1347 "let g:winManagerWindowLayout='FileExplorer,Taglist|BufExplorer'348 "使用WMToggle命令打开349 350 "============================================================351 "BufExplorer352 "Bundle 'bufexplorer.zip'353 354 "============================================================355 "NERD_tree 显示一棵目录树 与默认的FileExplorer类似356 "Bundle 'scrooloose/nerdtree'357 "下面是配置358 "let g:NERDTree_title="[目录树]"359 "使用NERDTreeToggle命令打开360 361 362 "============================================================363 "OmniCppComplete 自动补全加智能感应364 "进入要补全的源代码目录执行 ctags -R --c++-kinds=+p365 " --fields=+iaS366 " --extra=+q367 " 选项太多的话,会卡顿368 "下面是配置369 "Bundle 'OmniCppComplete'370 "set tags+=~371 "let OmniCpp_NamespaceSearch=1372 "let OmniCpp_GlobalScopeSearch=1373 "let OmniCpp_ShowAccess=1374 "let OmniCpp_ShowPrototypeInAbbr=1 "显示参数列表375 "let OmniCpp_MayCompleteDot=1 "输入.自动补全376 "let OmniCpp_MayCompleteArrow=1 "输入->自动补全377 "let OmniCpp_MayCompleteScope=1 "输入::自动补全378 "let OmniCpp_DefaultNamespaces=["std","_GLIBCXX_STD"]379 "set completeopt=menu,longest380 "au CursorMovedI,InsertLeave * if pumvisible()==0 | silent!pclose | endif381 "弹出下拉类别的颜色382 "hi Pmenu ctermbg=2 ...383 "hi PmenuSel ctermbg=5 ...384 385 386 "============================================================387 "SuperTab 加速补全388 "Bundle 'SuperTab'389 "就两个参数390 "let g:SuperTabRetainCompletionType=2391 "let g:SuperTabDefaultCompletionType=" "392 "imap 393 394 395 "============================================================396 "Visual-Mark 高亮书签397 "Bundle 'vim-scripts/Visual-Mark'398 "使用 mm 高亮399 400 401 "============================================================402 "Mark,vim 对选中的单词进行高亮403 Bundle 'vim-scripts/Mark--Karkat'404 "let mapleader="\"405 "用法 406 " m 标记/取消 407 " n 关闭 r 正值表达式标记408 " * 同组标记的下一个 # 同组标记的上一个409 " / 全部标记的下一个 ? 全部标记的上一个410 "高亮颜色411 "hi MarkWord1 ctermbg=...412 "hi MarkWord.413 "hi MarkWord6 ctermbg=...414 415 416 "============================================================417 "vim-multiple-cursors 多光标选择418 "该插件有bug419 "Bundle 'vim-multiple-cursors'420 "let g:multi_cursor_next_key=' '421 "let g:multi_cursor_prev_key=' '422 "let g:multi_cursor_skip_key=' '423 "let g:multi_cursor_quit_key=' '424 "用法425 "使用c-n选择 c,s 两个字母来替换 i,a 两个用来修改426 "用Visul 模式下选择多行然后进行正值表达式匹配427 " :'<,'> MultipleCursorsFind 428 429 430 "============================================================431 "vim-airline 修改状态条的颜色等信息 其实432 Bundle 'bling/vim-airline'433 "let g:airline_left_sep = '»'434 let g:airline_left_sep = '▶'435 let g:airline_left_alt_sep = '>'436 "let g:airline_right_sep = '«'437 let g:airline_right_sep = '◀'438 let g:airline_right_alt_sep = '<'439 "let g:airline_symbols.linenr = '␊'440 "let g:airline_symbols.linenr = ''441 "let g:airline_symbols.linenr = '¶'442 "let g:airline_symbols.branch = '⎇'443 "let g:airline_symbols.paste = 'ρ'444 "let g:airline_symbols.paste = 'Þ'445 "let g:airline_symbols.paste = '∥'446 "let g:airline_symbols.whitespace = 'Ξ'447 let g:airline_section_a=airline#section#create(['mode'])448 let g:airline_section_b=airline#section#create(['hunks'])449 let g:airline_section_c=airline#section#create(['%{getcwd()}','%f'])450 let g:airline_section_x=airline#section#create(['branch','ffenc'])451 let g:airline_section_y=airline#section#create(['','[TYPE:','filetype',']','[TIME:','%{strftime("%H:%M")}',']'])452 "let g:airline_section_z=airline#section#create()453 "let g:airline_section_a=454 "let g:airline_section_b='%{getcwd()}'455 "let g:airline_section_c=456 "let g:airline_section_x=airline#section#create(['mode',' ','branch',' ','ffenc'])457 "458 "let g:airline_section_y='%{FileType}'459 460 "let g:airline_section_y='%a'461 "let g:airline_section_z='%{strftime("%H:%M")}'462 "使用AirlineToggle打开 463 "AirlineTheme ... 来选择配色464 465 466 "============================================================467 "EasyMotion 快速定位移动468 Bundle 'EasyMotion'469 "let g:EasyMotion_leader_key=' '470 "用法471 " {motion} 472 " \\fo 表示向下查找所有o字母473 let g:EasyMotion_keys='abcdefghijklmnopqrstuvwxyz'474 let g:EasyMotion_do_shade=1 " 1表示背景有高亮475 " hi EasyMotionTarget ctermbg=...476 " hi EasyMotionShade ctermbg=...477 " hi link EasyMotionShade Comment478 479 480 "============================================================481 "css-color.vim 对css中颜色的值进行高亮,需要Gui482 "Bundle 'css_color.vim'483 484 485 "============================================================486 "AutoComplPop Acp自动弹出487 "Bundle 'AutoComplPop'488 "let g:acp_enableAtStartup=0489 "下面这个是设置只是对前端起作用,因为对其他支持不是很好490 "autocmd FileType html,css,htm,xml,jsp,php exec "AutoComplPopEnable"491 492 493 "============================================================494 "Javascript.vim 对js代码高亮495 "Bundle 'javascript.vim'496 "setlocal foldlevel=3 "折叠的层数497 "let b:javascript_fold=1498 "let javascript_enable_domhtmlcss=1 "对dom,html,css支持499 500 501 "============================================================502 "Emmet 插件 标签框架自动生成503 "Bundle 'mattn/emmet-vim'504 "let g:user_emmet_mode='niv' "表示insert,normal,visual模式505 "let g:user_emmet_install_global=0506 "autocmd FileType html,css,jsp,php,htm EmmetInstall "只对网页启用507 "let g:user_emmet_leader_key=' ' "默认是 508 "使用的方法509 " ul>li*4 然后 ,510 511 512 "============================================================