1、用到的vim基本配置
set t_Co=256 " necessary for AirlineTheme
set laststatus=2
set statusline=%F%m%r%h
set foldmethod=syntax
set tabstop=4
set relativenumber
set number
set fencs=utf-8,gbk
set cindent
set expandtab
set softtabstop=4
set showmatch
set smartcase
set autochdir
set autoread
set wildmenu
set wildmode=longest:list,full
let mapleader=";"
2、用到的插件
Vundle(管理插件) 已改用vimplug
YouCompleteMe(单词补全和跳转到声明/定义)由于下载问题,已改用coc.nvim
CtrlP(模糊搜索文件)
CtrlSF(搜索单词,需要提前装好ack)
Airline和AirlineTheme(美化状态栏,显示buffer)
gutentags ,gutentags_plus,ctags。
安装gtags前要先安装ctags,不然gtags快捷键用不了另外安装的ctags最新版本为 Universal CTags
3、Vundle安装
参考官网基本没啥问题,官网给的.vimrc的例子我只保留
Plugin 'VundleVim/Vundle.vim'
其他的Plugin都注释掉。
Vimplug的安装
Download plug.vim 并将其放到.vim/autoload目录下
4、其他插件的安装
" YouCompleteMe,auto complete word,goto
" definition or declaration
Plugin 'ycm-core/YouCompleteMe'
" airline,show status line at bottom and
" buffer at top of the window
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" ctrlp,search file vaguely
Plug 'ctrlpvim/ctrlp.vim'
" ctrlsf,search word gloable
Plug 'dyng/ctrlsf.vim'
注意YouCompleteMe下载较慢,直接通过VundleInstall很容易失败,我是选择先用git clone将其拷贝到本地进行安装,具体还是参考官网,中途没遇到啥问题。
5、配置
要注意AirlineTheme生效需要.vimrc中加上
set t_Co=256 " necessary for AirlineTheme
不然一直不生效,我在这里被坑了一会。
6、最后
奉上我的.vimrc
" #################### Vim ###########################################
set t_Co=256 " necessary for AirlineTheme
set laststatus=2
set backspace=2
set foldmethod=syntax
set foldlevel=100 "启动vim时不要自动折叠代码
set statusline=%F%m%r%h
set tabstop=4
set relativenumber
set number
set fencs=utf-8,gbk
set t_kb=^? " 解决backSpace无效
" set cindent
set noswapfile
set expandtab
set softtabstop=4
set showmatch
set smartcase
set autochdir
set autoread
set wildmenu
set wildmode=longest:list,full
set hlsearch
" set tags=./.tags;,.tags
" set tags=tags
set tags=./tags,./TAGS,tags;~,TAGS;~
set autochdir
set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
let mapleader = ' '
" set nocompatible " be iMproved, required
" filetype off " required
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
Plug 'junegunn/vim-easy-align'
" let Vundle manage YouCompleteMe,auto complete word,goto definition
" or declaration
" Plug 'ycm-core/YouCompleteMe'
" let Vundle manage airline,show status line at bottom and buffer at top of
" the window
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" let Vundle manage ctrlP,show status line at bottom and buffer at top of
" the window
Plug 'ctrlpvim/ctrlp.vim'
" let Vundle manage ctrlP,show status line at bottom and buffer at top of
" the window
Plug 'dyng/ctrlsf.vim'
" vim-gutentags,manage ctags or gtags
Plug 'ludovicchabant/vim-gutentags'
Plug 'skywind3000/gutentags_plus'
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
" Plug 'junegunn/vim-easy-align'
Plug 'vim-scripts/taglist.vim'
" coc.nvim "
" Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Or build from source code by using yarn: https://yarnpkg.com
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'}
" Any valid git URL is allowed
" Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" Multiple Plug commands can be written in a single line using | separators
" Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" On-demand loading
" Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Using a non-master branch
" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
" Plug 'fatih/vim-go', { 'tag': '*' }
" Plugin options
" Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
" Plugin outside ~/.vim/plugged with post-update hook
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Unmanaged plugin (manually installed and updated)
" Plug '~/my-prototype-plugin'
" Initialize plugin system
call plug#end()
" Put your non-Plugin stuff after this line
"" #################### YouCompleteMe ################################
"let g:ycm_server_python_interpreter='/usr/bin/python3'
"let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
"let g:ycm_show_diagnostics_ui = 0 "关闭语法提示
"let g:ycm_complete_in_comments=1 " 补全功能在注释中同样有效
"let g:ycm_confirm_extra_conf=0 " 允许 vim 加载 .ycm_extra_conf.py 文件,不再提示
"let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 标签补全引擎
"let g:ycm_min_num_of_chars_for_completion=1 " 从第一个键入字符就开始罗列匹配项
"let g:ycm_cache_omnifunc=0 " 禁止缓存匹配项,每次都重新生成匹配项
"let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全
"" let g:ycm_goto_buffer_command = 'horizontal-split' " 跳转打开上下分屏
"map :YcmCompleter GoToDefinitionElseDeclaration
" #################### Airline ######################################
" 使用powerline打过补丁的字体
" let g:airline_powerline_fonts = 1
" 开启tabline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#default#layout = [ [ 'a', 'b', 'c' ], [ 'x', 'y', 'z', 'error' ] ]
" let g:airline#extensions#default#layout = [ [ 'a' ], [ 'error', 'warning' ] ]
" tabline中当前buffer两端的分隔字符
let g:airline#extensions#tabline#left_sep = ' '
" tabline中未激活buffer两端的分隔字符
let g:airline#extensions#tabline#left_alt_sep = ' '
" tabline中buffer显示编号
" let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_theme='bubblegum'
" #################### CtrlP ################################
let g:ctrlp_map = ''
" let g:ctrlp_map = 'f'
let g:ctrlp_cmd = 'CtrlPMixed'
"let g:ctrlp_user_command = 'find %s -type f' "指定一个用于列出文件的外部工具
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)$',
\ 'file': '\v\.(exe|so|dll)$',
\ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
\ }
" #################### CtrlSF ################################
let g:ctrlsf_ackprg='ag'
" nnoremap f :CtrlSF
let g:ctrlsf_ignore_dir=[".git", ".svn"]
let g:ctrlsf_search_mode = 'async'
" let g:ctrlsf_mapping = 'w'
" nnoremap :CtrlSF
nnoremap w :CtrlSF
" let g:ctrlsf_cmd = 'CtrlSF'
let g:ctrlsf_default_root = 'project'
let g:ctrlsf_context = '-B 1 -A 1'
let g:ctrlsf_default_view_mode = 'compact'
" ###################### GTAGS ################################
" enable gtags module
let $GTAGSLABEL = 'native-pygments'
let $GTAGSCONF = '/usr/local/share/gtags/gtags.conf'
" let g:gutentags_modules = ['ctags', 'gtags_cscope']
"
" " config project root markers.
" let g:gutentags_project_root = ['.root']
"
" " generate datebases in my cache directory, prevent gtags files polluting my project
" let g:gutentags_cache_dir = expand('~/.cache/tags')
"
" " change focus to quickfix window after search (optional).
" let g:gutentags_plus_switch = 1
" #################### gutentags ##############################
" gutentags 搜索工程目录的标志,当前文件路径向上递归直到碰到这些文件/目录名
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 同时开启 ctags 和 gtags 支持:
let g:gutentags_modules = []
if executable('ctags')
let g:gutentags_modules += ['ctags']
endif
if executable('gtags-cscope') && executable('gtags')
let g:gutentags_modules += ['gtags_cscope']
endif
" 将自动生成的 ctags/gtags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let g:gutentags_cache_dir = expand('~/.cache/tags')
" 配置 ctags 的参数,老的 Exuberant-ctags 不能有 --extra=+q,注意
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
" 如果使用 universal ctags 需要增加下面一行,老的 Exuberant-ctags 不能加下一行
let g:gutentags_ctags_extra_args += ['--output-format=e-ctags']
" 禁用 gutentags 自动加载 gtags 数据库的行为
let g:gutentags_auto_add_gtags_cscope = 0
let g:gutentags_define_advanced_commands = 1
" #################### gutentags_plus #########################
" enable gtags module
let g:gutentags_modules = ['ctags', 'gtags_cscope']
" config project root markers.
let g:gutentags_project_root = ['.root']
" generate datebases in my cache directory, prevent gtags files polluting my project
let g:gutentags_cache_dir = expand('~/.cache/tags')
" forbid gutentags adding gtags databases
let g:gutentags_auto_add_gtags_cscope = 0
" change focus to quickfix window after search (optional).
let g:gutentags_plus_switch = 1
" How to use gutentags by shortcuts:
" | keymap | desc |
" |--------|------|
" | `cs` | Find symbol (reference) under cursor |
" | `cg` | Find symbol definition under cursor |
" | `cd` | Functions called by this function |
" | `cc` | Functions calling this function |
" | `ct` | Find text string under cursor |
" | `ce` | Find egrep pattern under cursor |
" | `cf` | Find file name under cursor |
" | `ci` | Find files #including the file name under cursor |
" | `ca` | Find places where current symbol is assigned |
" ##################### Tlist插件配置 ########################
let Tlist_Show_One_File = 1 " 只显示当前文件的tags
"let Tlist_Auto_Open = 1 " 打开vim自动打开Tlist
"let Tlist_GainFocus_On_ToggleOpen = 1 " 打开Tlist窗口时,光标跳到list窗口
let Tlist_Exit_OnlyWindow = 1 " 如果Tlist窗口是最后一个窗口则退出Vim
let Tlist_Use_Left_Window = 1 " 在左侧窗口中显示
let Tlist_File_Fold_Auto_Close = 1 " 自动折叠
let Tlist_Auto_Update = 1 " 自动更新
" 打开 Tlist 窗口,在左侧栏显示
map :TlistToggle
常见问题:
安装YCM
cd ~/.vim/plugged
git clone [email protected]:ycm-core/YouCompleteMe.git
cd ~/.vim/plugged/YouCompleteMe
git submodule update --init --recursive
打开VIM报错,The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). Unexpec...ype ':YcmToggleLogs ycmd_52255_stderr_mr3mi734.log' to check the logs.
cd ~/.vim/plugged/YouCompleteMe
sudo ./install.py
还是会报错,根据提示执行 git submodule update --init --recursive
还是下载失败,则哪个失败,就在这个path下clone哪个module
~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party
git clone xxx
mrab-regex下载失败
cd ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/mrab-regex
git clone https://bitbucket.org/mrabarnett/mrab-regex.git
安装coc.nvim
curl -sL install-node.vercel.app/lts | sudo bash //Install nodejs >= 12.12:
.vimrc中添加
" Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Or build from source code by using yarn: https://yarnpkg.com
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'}
执行:PlugInstall
cd ~/.vim/plugged/coc.nvim
yarn install
yarn build
yarn报错执行以下指令解决
sudo apt remove cmdtest
sudo apt remove yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn -y
yarn install
yarn build