Chinaunix首页 | 论坛 | 博客
  • 博客访问: 291350
  • 博文数量: 76
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-20 20:38
文章分类
文章存档

2016年(20)

2015年(56)

分类: 嵌入式

2016-04-23 09:26:29

vimrc.txt
折腾了好多天,终于将vim配置成自己想要的样子,里面附带了一些插件都是不错的。重要的是使用vundle来管理插件,现在插件都是采用github来托管了,使用vundle来管理插件的话,只需要带着这个.vimrc文件,随便换个电脑,很轻松地就将vim配置成自己熟悉的样子,简直不能再爽!!!唯一比较难配置的还是youcompleteme这个插件,另外对于括号补全,引号补全等,原来使用的是:inoremap来补全的,但是还是太难用,最终找到'jiangmiao/auto-pairs'这个插件,太完美了,下面就是.vimrc文件配置(另外,在复制粘贴的时候,下面的代码很可能出错不能执行,这个应该是网站的问题,我在另一个电脑上没法使用,于是又将.vimrc文件上传了,不过CU不支持这个文件格式,转成txt格式了):


"==========================================  
" 显示和字体设置  
"==========================================  
set nocompatible     " 非兼容vi模式。去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限   
set autoread          " 文件修改之后自动载入。  
set shortmess=atI       " 启动的时候不显示那个援助索马里儿童的提示
syntax on " 自动语法高亮
set number " 显示行号
set cursorline " 突出显示当前行
set ruler " 打开状态栏标尺
set tabstop=4 " 设定 tab 长度为 4
set shiftwidth=4 " 统一缩进为4
set softtabstop=4 " 统一缩进为4
filetype plugin indent on " 开启插件
set ignorecase smartcase " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set incsearch " 输入搜索内容时就显示搜索结果
set hlsearch " 搜索时高亮显示被找到的文本
set magic " 设置魔术
set clipboard+=unnamed "共享剪贴板
set nobackup "从不备份
set noswapfile "禁止生成临时文件
set showmatch " 高亮显示匹配的括号
set mouse=a   " Enable mouse usage (all modes)"使用鼠标



"==========================================  
" ctags 配置  
"==========================================
map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . :TlistUpdate
imap :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . :TlistUpdate
set tags=tags
set tags+=./tags "add current directory's generated tags file



"==========================================  
" 新建文件注释补全  
"==========================================
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
    "如果文件类型为.sh文件
    if &filetype == 'sh'
        call setline(1,"\#########################################################################")
        call append(line("."), "\# File Name: ".expand("%"))
        call append(line(".")+1, "\# Author: ZER0")
        call append(line(".")+2, "\# mail: 471685488@qq.com")
        call append(line(".")+3, "\# Created Time: ".strftime("%c"))
        call append(line(".")+4, "\#########################################################################")
        call append(line(".")+5, "\#!/bin/bash")
        call append(line(".")+6, "")
    else
        call setline(1, "/*************************************************************************")
        call append(line("."), "    > File Name: ".expand("%"))
        call append(line(".")+1, "    > Author: ZER0")
        call append(line(".")+2, "    > Mail: 471685488@qq.com")
        call append(line(".")+3, "    > Created Time: ".strftime("%c"))
        call append(line(".")+4, " ************************************************************************/")
        call append(line(".")+5, "")
    endif
    if &filetype == 'cpp'
        call append(line(".")+6, "#include")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif
    if &filetype == 'c'
        call append(line(".")+6, "#include")
        call append(line(".")+7, "")
    endif
    "新建文件后,自动定位到文件末尾
    autocmd BufNewFile * normal G
endfunc


"==========================================  
" vundle设置
"==========================================  
set nocompatible              " be iMproved, required
filetype off                  " required

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

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

" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'scrooloose/nerdtree'
Bundle 'majutsushi/tagbar'
Bundle 'bling/vim-airline'
Bundle 'scrooloose/syntastic'
Bundle 'jiangmiao/auto-pairs'
Bundle 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'L9'
Bundle 'FuzzyFinder'
Bundle 'kien/rainbow_parentheses.vim'
" scripts not on GitHub
Bundle 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" ...

filetype plugin indent on     " required
Bundle 'Valloric/YouCompleteMe'



"==========================================  
" NERDTree配置  
"==========================================
let NERDTreeWinPos='left' "在左边显示NERDTree"
let NERDTreeWinSize=20 "设置窗口大小为20"
let NERDTreeChDirMode=1
autocmd StdinReadPre * let s:std_in=1
autocmd vimenter * NERDTree "设置自动启动NERDTree"
wincmd w
autocmd VimEnter * wincmd w "这两行是设置启动NERDTree后光标焦点自动在右侧文件中"
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
map :NERDTreeToggle
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"如果NERDTree是最后一个窗口的话自动关闭"



"==========================================  
" tagbar配置  
"==========================================
let g:tagbar_ctags_bin='ctags'            "ctags程序的路径
let g:tagbar_width=30                    "窗口宽度的设置
map :Tagbar
let g:tagbar_autofocus = 1 " 启动时自动focus
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()     "如果是c语言的程序的话,tagbar自动开启




"==========================================  
" syntastic设置
"==========================================  
let g:syntastic_error_symbol='>>'
let g:syntastic_warning_symbol='>'
let g:syntastic_check_on_open=1
let g:syntastic_check_on_wq=0
let g:syntastic_enable_highlighting=1
let g:syntastic_python_checkers=['pyflakes'] " 使用pyflakes,速度比pylint快
let g:syntastic_javascript_checkers = ['jsl', 'jshint']
let g:syntastic_html_checkers=['tidy', 'jshint']
" 修改高亮的背景色, 适应主题
highlight SyntasticErrorSign guifg=white guibg=black

 " to see error location list
let g:syntastic_always_populate_loc_list = 0
let g:syntastic_auto_loc_list = 0
let g:syntastic_loc_list_height = 5
function! ToggleErrors()
    let old_last_winnr = winnr('$')
    lclose
    if old_last_winnr == winnr('$')
    " Nothing was closed, open syntastic error location panel
        Errors
   endif
endfunction
nnoremap s :call ToggleErrors()
   " nnoremap sn :lnext
   " nnoremap sp :lprevious



"==========================================  
" rainbow_parentheses.vim设置
"==========================================  
let g:rbpt_colorpairs = [
    \ ['brown',       'RoyalBlue3'],
    \ ['Darkblue',    'SeaGreen3'],
    \ ['darkgray',    'DarkOrchid3'],
    \ ['darkgreen',   'firebrick3'],
    \ ['darkcyan',    'RoyalBlue3'],
    \ ['darkred',     'SeaGreen3'],
    \ ['darkmagenta', 'DarkOrchid3'],
    \ ['brown',       'firebrick3'],
    \ ['gray',        'RoyalBlue3'],
    \ ['darkmagenta', 'DarkOrchid3'],
    \ ['Darkblue',    'firebrick3'],
    \ ['darkgreen',   'RoyalBlue3'],
    \ ['darkcyan',    'SeaGreen3'],
    \ ['darkred',     'DarkOrchid3'],
    \ ['red',         'firebrick3'],
    \ ]

" 不加入这行, 防止黑色括号出现, 很难识别
" " \ ['black',       'SeaGreen3'],
"
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces



"==========================================  
" vim-airline设置
"==========================================  
set nocompatible
set laststatus=2
set t_Co=256
let g:Powerline_symbols='unicode'
set encoding=utf-8

if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif
let g:airline_left_sep = '?'
let g:airline_left_alt_sep = '?'
let g:airline_right_sep = '?'
let g:airline_right_alt_sep = '?'
let g:airline_symbols.linenr = '?'
let g:airline_symbols.branch = '?'
" 关闭状态显示空白符号计数
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#symbol = '!'

" 是否打开tabline
" let g:airline#extensions#tabline#enabled = 1
" let g:airline#extensions#tabline#buffer_nr_show = 1



"==========================================  
" youcompleteme设置
"==========================================  
set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
inoremap        pumvisible() ? "\" : "\" "回车即选中当前项
"上下左右键的行为 会显示其他信息
inoremap      pumvisible() ? "\" : "\"
inoremap        pumvisible() ? "\" : "\"
inoremap pumvisible() ? "\\\" : "\"
inoremap    pumvisible() ? "\\\" : "\"

"youcompleteme  默认tab  s-tab 和自动补全冲突
"let g:ycm_key_list_select_completion=['']
let g:ycm_key_list_select_completion = ['']
"let g:ycm_key_list_previous_completion=['']
let g:ycm_key_list_previous_completion = ['']
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 :YcmForceCompileAndDiagnostics    "force recomile with syntastic
"nnoremap lo :lopen    "open locationlist
"nnoremap lc :lclose    "close locationlist
inoremap "在注释输入中也能补全
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:ycm_show_diagnostics_ui = 0 " 关闭ycm的syntastic

nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration "跳转到定义处
阅读(2615) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~