配置自动缩减
代码语言:javascript复制set nu
set autoindent
set cindent
set shiftwidth=4
set softtabstop=4
set tabstop=4
具体含义:
命令 | 含义 |
---|---|
nu | 添加行号 |
autoindent | 自动缩进 |
cindent | 按照c语言语法缩进 |
shiftwidth | 自动缩进空白字符个数 |
softtabstop | tab键的一个制表符,如果softtabstop=5,tabstop=4,则tab是1个制表符加1个空格的混合 |
tabstop | tab键的空格数 |
添加左分屏
左分屏用来显示当前文件夹下的所有文件。
代码语言:javascript复制" NERD tree
let NERDChristmasTree=0
let NERDTreeWinSize=35
let NERDTreeChDirMode=2
let NERDTreeIgnore=['~$', '.pyc$', '.swp$']
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:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" Open a NERDTree
nmap <F5> :NERDTreeToggle<cr>
使用F5来开启和关闭该功能。
添加右分屏
右分屏用来显示当前文件中的函数名,和全局对象名。
代码语言:javascript复制" Tagbar
let g:tagbar_width=35
let g:tagbar_autofocus=1
nmap <F6> :TagbarToggle<CR>
添加代码折叠
功能方法有待改善。。。不太好用
代码语言:javascript复制" Enable folding
set fdm=indent
" Enable folding with the spacebar
nnoremap <space> za
通过<space>键来展开和折叠代码块。
添加自动补全功能
该功能的使用需要安装YouCompleteMe。使用的是vbundle来管理插件。
代码语言:javascript复制set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)"
set runtimepath =~/.vim/bundle/YouCompleteMe
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口"
let g:ycm_collect_identifiers_from_tags_files = 1 " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释与字符串中的内容也用于补全
let g:syntastic_ignore_files=[".*.py$"]
let g:ycm_seed_identifiers_with_syntax = 1 " 语法关键字补全
let g:ycm_complete_in_comments = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>'] " 映射按键, 没有这个会拦截掉tab, 导致其他插>件的tab不能用.
let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
let g:ycm_complete_in_comments = 1 " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1 " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 0 " 禁用语法检查
" inoremap <expr> <CR> pumvisible() ? "<C-y>" : "<CR>" | " 回车即选中当前项
nnoremap <F3> :YcmCompleter GoToDefinitionElseDeclaration<CR>|
let g:ycm_min_num_of_chars_for_completion=2
vimrc文件全部内容
代码语言:javascript复制if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
set nu
set autoindent
set cindent
set shiftwidth=4
set softtabstop=4
set tabstop=4
" NERD tree
let NERDChristmasTree=0
let NERDTreeWinSize=35
let NERDTreeChDirMode=2
let NERDTreeIgnore=['~$', '.pyc$', '.swp$']
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:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" Open a NERDTree
nmap <F5> :NERDTreeToggle<cr>
" Tagbar
let g:tagbar_width=35
let g:tagbar_autofocus=1
nmap <F6> :TagbarToggle<CR>
" Enable folding
set fdm=indent
" Enable folding with the spacebar
nnoremap <space> za
set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)"
set runtimepath =~/.vim/bundle/YouCompleteMe
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口"
let g:ycm_collect_identifiers_from_tags_files = 1 " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释与字符串中的内容也用于补全
let g:syntastic_ignore_files=[".*.py$"]
let g:ycm_seed_identifiers_with_syntax = 1 " 语法关键字补全
let g:ycm_complete_in_comments = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>'] " 映射按键, 没有这个会拦截掉tab, 导致其他插>件的tab不能用.
let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
let g:ycm_complete_in_comments = 1 " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1 " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 0 " 禁用语法检查
" inoremap <expr> <CR> pumvisible() ? "<C-y>" : "<CR>" | " 回车即选中当前项
nnoremap <F3> :YcmCompleter GoToDefinitionElseDeclaration<CR>|
let g:ycm_min_num_of_chars_for_completion=2
运行实例: