先分别讲各个部分,最后给完整的~/.vimrc 文件
~/.vimrc 配置基础
自动补全
补全工具有YouCompleteMe / deoplete 等。 本文使用deoplete ,支持异步搜索补全内容。使用不同的插件补全不同的语言内容
配置
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
let g:deoplete#enable_at_startup = 1
安装 python3 的插件工具
pip3 install --user pynvim
语法检查[lint]
语法检查工具有 ale / vim-polyglot等。 在github上查询,ale 的start及fork 数量远多于vim-polyglot 。因而选前者。
Plug 'w0rp/ale'
let g:ale_linters = {
'javascript': ['eslint'],
'css': ['stylelint'],
}
let g:ale_fixers = {
'javascript': ['eslint'],
'css': ['stylelint'],
}
let g:ale_fix_on_save = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '●'
let g:ale_sign_warning = '?'
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
全局搜索
常用的插件有 ctrlp / the_silver_searcher / ag.vim / mru.vim 等。 其中,the_silver_searcher 在的github的star 最多,使用这个插件。
代码注释
使用NerdCommenter
Plug 'scrooloose/nerdcommenter'
# <leader>c<space> 注释/取消注释
# <leader>cc // 注释
# <leader>cm 只用一组符号注释
# <leader>cA 在行尾添加注释
# <leader>c$ /* 注释 */
# <leader>cs /* 块注释 */
# <leader>cy 注释并复制
# <leader>ca 切换 // 和 /* */
# <leader>cu 取消注释
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
let g:NERDCustomDelimiters = {
'javascript': { 'left': '//', 'leftAlt': '/**', 'rightAlt': '*/' },
'less': { 'left': '/**', 'right': '*/' }
}
let g:NERDAltDelims_javascript = 1
let g:NERDDefaultNesting = 0
Git 集成
vim-gitgutter vim-fugitive 后者start更多一些
完整配置(.vimrc)
" show line number
set nu
" enable syntax
syntax on
filetype plugin on
colorscheme github-light
" highlight current line
set cursorline
" replace tab with blank-space
set ts=4
set expandtab
set shiftwidth=4
call plug#begin()
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" - Vim (Windows): '~/vimfiles/plugged'
" - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
" - e.g. `call plug#begin('~/.vim/plugged')`
" - Avoid using standard Vim directory names like 'plugin'
" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
" Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" On-demand loading
Plug 'scrooloose/nerdtree'|
\ Plug 'Xuyuanp/nerdtree-git-plugin' |
\ Plug 'ryanoasis/vim-devicons'
Plug 'scrooloose/nerdcommenter'
" Plugin for syntax checking, refactoring
Plug 'dense-analysis/ale'
" vim interface for ag (the siler-searcher)
Plug 'mileszs/ack.vim'
" git integration
Plug 'tpope/vim-fugitive'
"Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Using a non-default branch
"Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Initialize plugin system
call plug#end()
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" NERDTree Config
" automatically run NERDTree
autocmd vimenter * NERDTree
let g:NERDTreeMinimalUI = 1
" default: 0
let g:NERDTreeGitStatusShowClean = 1
" default: 0
let g:NERDTreeGitStatusConcealBrackets = 1
let g:NERDTreeGitStatusIndicatorMapCustom = {
\ 'Modified' :'?',
\ 'Staged' :'?',
\ 'Untracked' :'?',
\ 'Renamed' :'?',
\ 'Unmerged' :'═',
\ 'Deleted' :'?',
\ 'Dirty' :'?',
\ 'Ignored' :'?',
\ 'Clean' :'??',
\ 'Unknown' :'?',
\ }
nnoremap <leader>nc :NERDTreeFocus<CR>
nnoremap <leader>nn :NERDTree<CR>
nnoremap <leader>nt :NERDTreeToggle<CR>
nnoremap <leader>nr :NERDTreeRefreshRoot<CR>
" o : open / close directory
" e : open directory by way of file-manager
" t : open in tab
" T : open in tab, not cursor in NERDTree
" r : refresh current directory
" R : refresh root directory
" X : unfold all directory
" p : go father directory
" P : to to root directory
" J : go to first node
" K : go to last node
" I : hide/show hiddne file
" m : show file menu
" C : set current directory as root directory
" u : set father directory as root directory
" [autocompletion] / [deoplete]
"
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
let g:deoplete#enable_at_startup = 1
" [autocompletion] / [ale]
"
" Use ALE and also some plugin 'foobar' as completion sources for all code.
call deoplete#custom#option('sources', { '_': ['ale', 'foobar'],})
" set this variable to 1 to fix files when you save them.
let g:ale_fix_on_save = 1
" triggering completion manually with <C-x><C-o>.
set omnifunc=ale#completion#OmniFunc
let g:ale_completion_autoimport = 1
" use statusbar (by 'Airline') to show error msgs
let g:airline#extensions#ale#enabled = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '●'
let g:ale_sign_warning = '?'
" use 'Ctrl+j' and 'Ctrl+k' to moving between errors for example
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
" use 'quickfix' instead of 'loclist'
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
" open quickfix list
let g:ale_open_list = 1
" Useful if you are combining ALE with
" some other plugin which sets quickfix errors, etc.
let g:ale_keep_list_window_open = 1
" Show 5 lines of errors (default: 10)
" let g:ale_list_window_size = 5
" To save power
" let g:ale_lint_on_text_changed = 'never'
" let g:ale_lint_on_insert_leave = 0
" You can disable this option too
" if you don't want linters to run on opening a file
" let g:ale_lint_on_enter = 0
nnoremap gD:ALEGoToDefinition<CR>
nnoremap gR:ALEFindReferences<CR>
nnoremap gS:ALESymbolSearch<CR>
" [ searcher ] / [the silver searcher]
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
"? a quick summary of these keys, repeat to close
"o to open (same as Enter)
"O to open and close the quickfix window
"go to preview file, open but maintain focus on ack.vim results
"t to open in new tab
"T to open in new tab without moving to it
"h to open in horizontal split
"H to open in horizontal split, keeping focus on the results
"v to open in vertical split
"gv to open in vertical split, keeping focus on the results
"q to close the quickfix window
" <leader>c<space> 注释/取消注释
" <leader>cc // 注释
" <leader>cm 只用一组符号注释
" <leader>cA 在行尾添加注释
" <leader>c$ /* 注释 */
" <leader>cs /* 块注释 */
" <leader>cy 注释并复制
" <leader>ca 切换 // 和 /* */
" <leader>cu 取消注释
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
let g:NERDCustomDelimiters = {
\ 'javascript': { 'left': '//', 'leftAlt': '/**', 'rightAlt': '*/' },
\ 'less': { 'left': '/**', 'right': '*/' }
\}
let g:NERDAltDelims_javascript = 1
let g:NERDDefaultNesting = 0
参考 网页1
|