vim开发环境配置

目前还比较low,不能熟练使用各种快捷键,先参照往上大神的教程配置一个自己的,后续再慢慢完善。

https://www.jianshu.com/p/923aec861af3

其他常用插件都好说,可以通过Vundle来管理。

git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

YCM一般无法直接通过Vundle安装成功,可以先下载源码,更新第三方依赖后,通过自带的install.sh安装:

$git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe

$git submodule update --init --recursive

在ubuntu上安装YouCompleteMe的时候,可能会碰到的问题是无法加载可用的python

ERROR: found static Python library (/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.a) but a dynamic one is required. You must use a Python compiled with the --enable-shared flag. If using pyenv, you need to run the command:
  export PYTHON_CONFIGURE_OPTS="--enable-shared"

这个是因为ubuntu apt安装的vim版本太久,可以从源码编译安装一遍vim,使得vim可以支持python, 具体见:

https://github.com/ycm-core/YouCompleteMe/wiki/Building-Vim-from-source

$./install.sh --clang-completer

我目前的.vimrc内容:

autocmd bufwritepost .vimrc source $MYVIMRC
set guifont=Meslo\ LG\ S\ DZ\ Regular\ for\ Powerline:h13
set enc=utf-8
set backspace=indent,eol,start " more powerful backspacing


" 设置外观-----------------------——---------
set number                    "显示行号
set showtabline=0             "隐藏顶部标签栏
set guioptions-=r            "隐藏右侧滚动条
set guioptions-=L            "隐藏左侧滚动条
set guioptions-=b            "隐藏底部滚动条
set cursorline                "突出显示当前行
set cursorcolumn            "突出显示当前列
set langmenu=zh_CN.UTF-8    "显示中文菜单
" 代码辅助----------------------------------
syntax on                    "开启语法高亮
set cindent                    "设置C样式的缩进格式
set tabstop=4                "一个tab显示出来是多少个空格,默认8
set shiftwidth=4            "每一级缩进是多少空格
set showmatch                "显示匹配的括号
set mouse=a                    "启用鼠标

" 包管理-----------------------------------
set nocompatible            "required
filetype off                "required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
    Plugin 'gmarik/Vundle.vim'
    Plugin 'L9'
    Plugin 'Lokaltog/vim-powerline'
    Plugin 'scrooloose/nerdtree'
    Plugin 'Xuyuanp/nerdtree-git-plugin'
    Plugin 'Yggdroot/indentLine'
    Plugin 'Valloric/YouCompleteMe'
    Plugin 'octol/vim-cpp-enhanced-highlight'
    Plugin 'jiangmiao/auto-pairs'
    Plugin 'vim-scripts/indentpython.vim'
    Plugin 'tell-k/vim-autopep8'

" 配置NERDTree-----------------------------
" 使用F3键快速调出和隐藏它
map <F3> :NERDTreeToggle<CR>
let NERDTreeChDirMode=1
" 显示书签
let NERDTreeShowBookmarks=1
" 设置忽略文件类型
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
" 窗口大小
let NERDTreeWinSize=25
" 修改默认箭头
let g:NERDTreeDirArrowExpandable='▸'
let g:NERDTreeDirArrowCollapsible='▾'

"How can I open a NERDTree automatically when vim starts up if no files were specified?
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

"打开vim时自动打开NERDTree
autocmd vimenter * NERDTree

"How can I open NERDTree automatically when vim starts up on opening a directory?
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif

" 关闭vim时,如果打开的文件除了NERDTree没有其他文件时,它自动关闭,减少多次按:q!
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" 开发的过程中,我们希望git信息直接在NERDTree中显示出来, 和Eclipse一样,修改的文件和增加的文件都给出相应的标注, 这时需要安装的插件就是 nerdtree-git-plugin,配置信息如下
let g:NERDTreeGitStatusIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ "Unknown"   : "?"
    \ }

" 显示行号
let NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1

" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1


" 配置YCM---------------------------------
" 补全菜单的开启与关闭
set completeopt=longest,menu                    " 让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
let g:ycm_min_num_of_chars_for_completion=2             " 从第2个键入字符就开始罗列匹配项
let g:ycm_cache_omnifunc=0                      " 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_autoclose_preview_window_after_completion=1       " 智能关闭自动补全窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif         " 离开插入模式后自动关闭预览窗口

" 补全菜单中各项之间进行切换和选取:默认使用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>']
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"    " 回车即选中补全菜单中的当前项

" 开启各种补全引擎
let g:ycm_collect_identifiers_from_tags_files=1         " 开启 YCM 基于标签引擎
let g:ycm_auto_trigger = 1                  " 开启 YCM 基于标识符补全,默认为1
let g:ycm_seed_identifiers_with_syntax=1                " 开启 YCM 基于语法关键字补全
let g:ycm_complete_in_comments = 1              " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1               " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0 " 注释和字符串中的文字也会被收入补全

" 重映射快捷键
"上下左右键的行为 会显示其他信息,inoremap由i 插入模式和noremap不重映射组成,只映射一层,不会映射到映射的映射
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>"

"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>

nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处
let g:ycm_confirm_extra_conf=0                  " 关闭加载.ycm_extra_conf.py确认提示


" 分割布局-------------------------------
set splitbelow                                    " 允许在下部分割布局
set splitright                                    " 允许在右侧分割布局
" 组合快捷键
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" 按照PEP8标准来配置vim
au BufNewFile,BufRead *.py set tabstop=4 |set softtabstop=4|set shiftwidth=4|set textwidth=79|set expandtab|set autoindent|set fileformat=unix

" All of your plugins must be added before the following line
call vundle#end()
filetype plugin indent on    "required

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值