vim的配置和插件安装

  由于自己对自己未来的规划是做一个服务器后端开发人员,所以虽然自己非常不习惯,但还是开始了将自己的开发平台转往Linux的路程,那么自然而然我便要开始学习vim的使用。
  但是在linux上裸装的vim是万万不能满足自己的要求的(但也可能是自己的水品太烂用不起来),我便开始在网上各种搜集资料来配置属于自己的vim。
  刚开始只知道vim可以配置,便在vimrc上咕咕叨叨,从网上大神的vimrc配置中挑出自己觉得挺有必要的一些配了一下,开个cpp文件,但还是感觉和以前用的vs比不太方便(因为以前只用过ide来开发)。在查配置的过程中知道了vim还可以安装各种吊炸天的插件。于是又开始不停地尝试安装插件。
  要安装插件,首先必不可少的就是安装vundle了,但一开始安装完vundle后一位还是要将其他的插件单独下载下来才能安装,但网上各种教程都没有提到下载下来怎么继续操作,折腾半天后才发现原来我一开始就弄错了,只需要在vimrc中添加要安装的插件名称,再在vim中调用PluginInstall就可以很简单的完成插件的安装。
  但即使如此,我在安装YouCompleteme这个插件时还是出现了问题,我看了很多人的博客,但很多博客描述的安装方法并不一样,而且很繁琐,我按照这些方法装了很久都没有安装成功,最后还是在youcompleteme的github官方网页上才发现了正确的方法,而且很简单。装完之后,我发现很多时候,第一选择应该是在官方网站上寻求安装的帮助文档,虽然是英文文档,但是它可以保证安装的正确性,而且,即使是英文文档,只要耐心点,其实也没有什么难度,最起码说,要比在网上那么多杂乱无章的方法中找一个正确的方法要简单点(但不排除有些插件网上的方法都很正确和简单),而且也能够节省时间。下面附上我的vimrc配置和选择使用的插件(只是个最初版本,肯定会随着以后的使用而不停更改)。

"set showcmd        " Show (partial) command in status line.
"set showmatch      " Show matching brackets.
"set ignorecase     " Do case insensitive matching
"set smartcase      " Do smart case matching
"set incsearch      " Incremental search
"set autowrite      " Automatically save before commands like :next and :make
"set hidden     " Hide buffers when they are abandoned
"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
  set nu
  set tabstop=4
  set nobackup
  set ruler
  set smartindent
  vmap <C-c> "+y
  set nobackup
  set noswapfile

  set enc=utf-8
  set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
  set langmenu=zh_CN,UTF-8
  set helplang=cn
  set smartindent
  colorscheme desert
  set ignorecase smartcase
  set noerrorbells


set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/syntastic'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
Plugin 'bling/vim-airline'
Plugin 'Valloric/YouCompleteMe'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
Plugin 'The-NERD-tree'

" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)


" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
"Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

" tagbar configure

nmap <silent> <F4> :TagbarToggle<CR>
let g:tagbar_ctags_bin='/usr/bin/ctags'
let g:tagbar_width=30
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()

"nerdTree configure

nmap <F2> :NERDTree <CR>
let g:NERDTreeWinPos="left"
let g:NERDTreeWinSize=25
let g:NERDTreeShowLineNumbers=1
let g:neocomplcache_enable_at_startup = 1

"youcompleteme configure

"filetype off                  " required!
"set rtp+=~/.vim/bundle/vundle/
"call vundle#rc()
" Plugin 'Valloric/YouCompleteMe'
"filetype plugin indent on     " required!
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

"#####YouCompleteMe Configure   
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'  
" 自动补全配置  
set completeopt=longest,menu
"让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)  
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
"离开插入模式后自动关闭预览窗口  
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"
"回车即选中当前项  
"上下左右键的行为 会显示其他信息  
inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"  
inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"  
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" :
"\<PageDown>"  
inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" :
"\<PageUp>"  
   
"youcompleteme  默认tab  s-tab 和自动补全冲突  
"let g:ycm_key_list_select_completion=['<c-n>']  
let g:ycm_key_list_select_completion = ['<Down>']  
"let g:ycm_key_list_previous_completion=['<c-p>']  
let g:ycm_key_list_previous_completion = ['<Up>']  
let g:ycm_confirm_extra_conf=0 "关闭加载.ycm_extra_conf.py提示  
     
let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎  
let g:ycm_min_num_of_chars_for_completion=2 "
"从第2个键入字符就开始罗列匹配项  

let g:ycm_cache_omnifunc=0  " 禁止缓存匹配项,每次都重新生成匹配项  
let g:ycm_seed_identifiers_with_syntax=1    " 语法关键字补全  
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>    
"force recomile with syntastic  
"nnoremap <leader>lo :lopen<CR> "open locationlist  
"nnoremap <leader>lc :lclose<CR>    "close locationlist  
inoremap <leader><leader> <C-x><C-o>  
"在注释输入中也能补全  
let g:ycm_complete_in_comments = 1  
"在字符串输入中也能补全  
let g:ycm_complete_in_strings = 1  
"注释和字符串中的文字也会被收入补全  
let g:ycm_collect_identifiers_from_comments_and_strings = 0  
let g:clang_user_options='|| exit 0'  
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> "
" 跳转到定义处  
" #####YouCompleteMe Configure 

"syntastic configure
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

"kuohao buquan
inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {<CR>}<Esc>O
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>

function ClosePair(char)
	if getline('.')[col('.') - 1] == a:char
		return "\<Right>"
	else
		return a:char
	endif
endf

function QuoteDelim(char)
	let line = getline('.')
	let col = col('.')
	if line[col - 2] == ""
		return a:char
	elseif line[col - 1] == a:char
		return "\<Right>"
	else
		return a:char.a:char."\<Esc>i"
	endif
endf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值