vi ~/.vimrc
"注释掉鼠标所有模式
"set mouse=a " Enable mouse usage (all modes)
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
在以上代码后面追加:
"备注:没有安装的插件可以不添加相关插件的配置
"""""""""""""""""""""""""""""""""""Vundle"""""""""""""""""""""""""""""""""""
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim "设置运行时路径
call vundle#begin() " vundle初始化, 需要配置的插件都放在begin和end中间
Plugin 'VundleVim/Vundle.vim' "Vundle
"指定插件的来源
Plugin 'L9' " plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'git://git.wincent.com/command-t.git' " Git plugin not hosted on GitHub
Plugin 'alvan/vim-closetag' " plugin on GitHub repo
Plugin 'file:///home/gmarik/path/to/plugin' " git repos on your local machine (i.e. when working on your own plugin)
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} " The sparkup vim script is in a subdirectory of this repo called vim.
"Plugin 'user/L9', {'name': 'newL9'} " Avoid a name conflict with L9
"自己需要的插件
Plugin 'bronson/vim-trailing-whitespace' "行末空格高亮插件
Plugin 'taglist.vim' "Taglist
Plugin 'majutsushi/tagbar' "Tagbar
Plugin 'https://github.com/universal-ctags/ctags.git' "Ctags
Plugin 'https://github.com/scrooloose/nerdtree.git' "Nerdtree
Plugin 'https://github.com/Valloric/YouCompleteMe.git' "YouCompleteMe
call vundle#end()
"""""""""""""""""""""""""""""""""""Vundle"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""基本设置"""""""""""""""""""""""""""""""""""
filetype on "开启文件类型侦测
filetype plugin on "根据侦测到的不同类型加载对应的插件
filetype indent on "适应不同语言的智能缩进
syntax on "语法高亮
set showcmd "命令行显示输入的命令
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" 设置文字编码自动识别
set fencs=utf-8,cp936
"行号显示,取消快捷键设置,F3显示行号, F4不显示行号
nmap <F3> :set nu<CR>
nmap <F4> :set nonu<CR>
"搜索操作
set hlsearch "搜索设置高亮
set incsearch "开启实时搜索功能
"set ignorecase "搜索时大小写不敏感
set iskeyword+=_,$,@,%,#,-
set wildmenu
set whichwrap+=<,>,h,l
set report=0
set showmatch
set autoindent "设置自动对齐
set smartindent "智能对齐
set cindent
set cursorline
set ruler
set clipboard+=unnamed "设置vim中默认使用选择缓冲区寄存器
set wildmenu "vim 自身命令行模式智能补全
" 自动补全 ' ) ] }"
inoremap ' ''<ESC>i
inoremap " ""<ESC>i
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap { {<CR>}<ESC>O
"显示设置
set ruler "显示光标位置
set number "显示行号
set cursorline "高亮显示当前行
"状态栏设置
set laststatus=2 "总是显示状态栏
"状态栏显示完整路径
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&fileencoding}\ %c:%l/%L%)\ [%p%%]\
set statusline=%F%m%r%h%w\[POS=%l,%v][%p%%]\%{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"自动缩进与C语言风格缩进
set autoindent
set cindent
"缩进宽度
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent "打开自动缩进
"switch case 对齐风格
set cino=g0,:0
"vim backspace键只能删除到行首,无法跳到上一行继续删除
set backspace=2
"""""""""""""""""""""""""""""""""基本设置"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""ctags""""""""""""""""""""""""""""""""""""""
set tags=tags;/
set autochdir
"""""""""""""""""""""""""""""""""ctags""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""Taglist"""""""""""""""""""""""""""""""""""
let Tlist_Sort_Type = 'name' "以名称顺序排序,默认以位置顺序(order)
let Tlist_Show_One_File = 0 "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_File_Fold_Auto_Close = 1 "当光标不在编辑文件里面的时候全部折叠
let Tlist_Use_Right_Window = 0 "在右侧窗口中显示taglist窗口
let Tlist_Enable_Fold_Column = 1 "显示折叠边栏
let Tlist_Auto_Open = 0 "自动打开taglist
let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表,设置为1时不同时显示>多个文件的tag,只显示当前文件的
""""""""""""""""""""""""""""""""""Taglist"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""cscope"""""""""""""""""""""""""""""""""""""
set cscopequickfix=s-,c-,d-,i-,t-,e-
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
"""""""""""""""""""""""""""""""""cscope"""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""Tagbar"""""""""""""""""""""""""""""""""""
let g:tagbar_width=35 "宽度
let g:tagbar_ctags_bin='/usr/bin/ctags' "设置tagbar使用的ctags的插件
let g:tagbar_right=1 "位置在右侧
let g:tagbar_autofocus=0 "是否自动聚焦
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen() "打开文件自动打开tagbar
nmap <F6> :TagbarToggle<CR>
"""""""""""""""""""""""""""""""""""Tagbar"""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""NERD tree"""""""""""""""""""""""""""""""""""
let NERDChristmasTree=0
let NERDTreeWinSize=35
let NERDTreeChDirMode=2
let NERDTreeIgnore=['\~$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos="left"
" Automatically open a NERDTree if no files where specified
autocmd vimenter * if !argc() | NERDTree | endif
" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Open a NERDTree
nmap <F5> :NERDTreeToggle<cr>
""""""""""""""""""""""""""""""""NERD tree"""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""YouCompleteMe"""""""""""""""""""""""""""""""
"自动开启语义补全
let g:ycm_seed_identifiers_with_syntax = 1
"在注释中也开启补全
let g:ycm_complete_in_comments = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"字符串中也开启补全
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_tags_files = 1
"开启基于tag的补全,可以在这之后添加需要的标签路径
let g:ycm_collect_identifiers_from_tags_files = 1
"开始补全的字符数
let g:ycm_min_num_of_chars_for_completion = 2
"补全后自动关闭预览窗口
let g:ycm_autoclose_preview_window_after_completion = 1
"禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
"离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
"语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1
"在实现和声明之间跳转,并分屏打开
let g:ycm_goto_buffer_command = 'horizontal-split'
nnoremap <Leader>g :YcmCompleter GoTo<CR>
""""""""""""""""""""""""""""""""YouCompleteMe"""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""末尾空格处理""""""""""""""""""""""""""""""""
map <leader><space> :FixWhitespace<cr>
"<leader><space> "\+space, 即可去掉全部行为空格
""""""""""""""""""""""""""""""""末尾空格处理""""""""""""""""""""""""""""""""
以上内容在.vimrc以下两句之前,保存就会生效,不需要source
execute pathogen#infect()
call pathogen#helptags()