NeoVim 是一款非常优秀的软件,并且它有着很多非常好用的插件,以下为一些基础配置与插件的安装。

1. 安装Vim插件支持

  1. $ mkdir ~/.config/nvim
  2. $ touch ~/.config/nvim/init.vim
  3. $ curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://gitee.com/c4pr1c3/vim-plug/raw/master/plug.vim

2. 安装插件

init.vim 文件中添加如下内容:

  1. call plug#begin('~/.vim/plugged')
  2. Plug 'crusoexia/vim-monokai'
  3. Plug 'vim-airline/vim-airline'
  4. Plug 'vim-airline/vim-airline-themes' "airline 的主题
  5. Plug 'scrooloose/nerdcommenter'
  6. Plug 'luochen1990/rainbow'
  7. Plug 'preservim/nerdtree'
  8. Plug 'Xuyuanp/nerdtree-git-plugin'
  9. Plug 'octol/vim-cpp-enhanced-highlight'
  10. Plug 'honza/vim-snippets'
  11. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  12. Plug 'morhetz/gruvbox'
  13. Plug 'numirias/semshi', {'do' : ':UpdateRemotePlugins'}
  14. Plug 'neomake/neomake'
  15. Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
  16. Plug 'zchee/deoplete-jedi'
  17. Plug 'jiangmiao/auto-pairs'
  18. " 功能相关
  19. Plug 'Raimondi/delimitMate' " 自动加括号,换行等
  20. Plug 'Yggdroot/indentLine' " 缩进线
  21. Plug 'tyru/caw.vim'
  22. Plug 'Chiel92/vim-autoformat' " 代码格式化
  23. Plug 'Lokaltog/vim-easymotion' " 快速跳转
  24. Plug 'majutsushi/tagbar' " TagBar
  25. Plug 'tpope/vim-fugitive'
  26. Plug 'NLKNguyen/papercolor-theme'
  27. Plug 'powerman/vim-plugin-AnsiEsc' " 显示ansi color"
  28. Plug 'pboettch/vim-highlight-cursor-words' " 高亮光标单词
  29. Plug 'liuchengxu/vista.vim' " vista
  30. Plug 'editorconfig/editorconfig-vim' " editorconfig
  31. Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
  32. Plug 'junegunn/fzf.vim'
  33. Plug 'airblade/vim-rooter'
  34. " syntax
  35. Plug 'ekalinin/Dockerfile.vim' " Dockerfile
  36. Plug 'leshill/vim-json' " JSON
  37. Plug 'digitaltoad/vim-pug' " Pug
  38. Plug 'nikvdp/ejs-syntax' " ejs
  39. Plug 'mustache/vim-mustache-handlebars' " hbs
  40. Plug 'leafgarland/typescript-vim' " typescript
  41. Plug 'chemzqm/wxapp.vim' " 小程序
  42. Plug 'posva/vim-vue'
  43. Plug 'voldikss/vim-translator'
  44. Plug 'tpope/vim-surround'
  45. Plug 'tpope/vim-repeat'
  46. Plug 'junkblocker/git-time-lapse' " 类似于git lens
  47. " Mac
  48. " Plug 'APZelos/blamer.nvim'
  49. " Plug 'scrooloose/nerdcommenter' " 注释插件
  50. " Plug 'tpope/vim-commentary'
  51. " Plug 'mxw/vim-jsx'
  52. " Plug 'digitaltoad/vim-jade'
  53. " Plug 'cakebaker/scss-syntax.vim'
  54. " Plug 'tpope/vim-haml'
  55. " Plug 'w0rp/ale'
  56. " Plug 'SirVer/ultisnips' " 代码块
  57. " Plug 'mattn/emmet-vim' " Emmet神器
  58. " Plug 'ap/vim-css-color' " CSS颜色显示
  59. " Plug 'itchyny/lightline.vim'
  60. call plug#end()
  61. let g:indent_guides_guide_size = 1 " 指定对齐线的尺寸
  62. let g:indent_guides_start_level = 2 " 从第二层开始可视化显示缩进
  63. " 设置状态栏
  64. let g:airline#extensions#tabline#enabled = 1
  65. let g:airline#extensions#tabline#left_alt_sep = '|'
  66. let g:airline#extensions#tabline#buffer_nr_show = 0
  67. let g:airline#extensions#tabline#formatter = 'default'
  68. let g:airline_theme = 'desertink' " 主题
  69. let g:airline#extensions#keymap#enabled = 1
  70. let g:airline#extensions#tabline#buffer_idx_mode = 1
  71. let g:airline#extensions#tabline#buffer_idx_format = {
  72. \ '0': '0 ',
  73. \ '1': '1 ',
  74. \ '2': '2 ',
  75. \ '3': '3 ',
  76. \ '4': '4 ',
  77. \ '5': '5 ',
  78. \ '6': '6 ',
  79. \ '7': '7 ',
  80. \ '8': '8 ',
  81. \ '9': '9 '
  82. \}
  83. " 设置切换tab的快捷键 <\> + <i> 切换到第i个 tab
  84. nmap <leader>1 <Plug>AirlineSelectTab1
  85. nmap <leader>2 <Plug>AirlineSelectTab2
  86. nmap <leader>3 <Plug>AirlineSelectTab3
  87. nmap <leader>4 <Plug>AirlineSelectTab4
  88. nmap <leader>5 <Plug>AirlineSelectTab5
  89. nmap <leader>6 <Plug>AirlineSelectTab6
  90. nmap <leader>7 <Plug>AirlineSelectTab7
  91. nmap <leader>8 <Plug>AirlineSelectTab8
  92. nmap <leader>9 <Plug>AirlineSelectTab9
  93. " 设置切换tab的快捷键 <\> + <-> 切换到前一个 tab
  94. nmap <leader>- <Plug>AirlineSelectPrevTab
  95. " 设置切换tab的快捷键 <\> + <+> 切换到后一个 tab
  96. nmap <leader>+ <Plug>AirlineSelectNextTab
  97. " 设置切换tab的快捷键 <\> + <q> 退出当前的 tab
  98. nmap <leader>q :bp<cr>:bd #<cr>
  99. " 修改了一些个人不喜欢的字符
  100. if !exists('g:airline_symbols')
  101. let g:airline_symbols = {}
  102. endif
  103. let g:airline_symbols.linenr = "CL" " current line
  104. let g:airline_symbols.whitespace = '|'
  105. let g:airline_symbols.maxlinenr = 'Ml' "maxline
  106. let g:airline_symbols.branch = 'BR'
  107. let g:airline_symbols.readonly = "RO"
  108. let g:airline_symbols.dirty = "DT"
  109. let g:airline_symbols.crypt = "CR"
  110. "add spaces after comment delimiters by default
  111. let g:NERDSpaceDelims = 1
  112. " python 自动的会多加一个空格
  113. au FileType python let g:NERDSpaceDelims = 0
  114. " Use compact syntax for prettified multi-line comments
  115. let g:NERDCompactSexyComs = 1
  116. " Align line-wise comment delimiters flush left instead of following code indentation
  117. let g:NERDDefaultAlign = 'left'
  118. " Set a language to use its alternate delimiters by default
  119. let g:NERDAltDelims_java = 1
  120. " Add your own custom formats or override the defaults
  121. " let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
  122. " Allow commenting and inverting empty lines (useful when commenting a region)
  123. let g:NERDCommentEmptyLines = 1
  124. " Enable trimming of trailing whitespace when uncommenting
  125. let g:NERDTrimTrailingWhitespace = 1
  126. " Enable NERDCommenterToggle to check all selected lines is commented or not
  127. let g:NERDToggleCheckAllLines = 1
  128. let g:rainbow_active = 1
  129. let g:rainbow_conf = {
  130. \ 'guifgs': ['darkorange3', 'seagreen3', 'royalblue3', 'firebrick'],
  131. \ 'ctermfgs': ['lightyellow', 'lightcyan','lightblue', 'lightmagenta'],
  132. \ 'operators': '_,_',
  133. \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
  134. \ 'separately': {
  135. \ '*': {},
  136. \ 'tex': {
  137. \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
  138. \ },
  139. \ 'lisp': {
  140. \ 'guifgs': ['darkorange3', 'seagreen3', 'royalblue3', 'firebrick'],
  141. \ },
  142. \ 'vim': {
  143. \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
  144. \ },
  145. \ 'html': {
  146. \ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
  147. \ },
  148. \ 'css': 0,
  149. \ }
  150. \}
  151. " autocmd vimenter * NERDTree "自动开启Nerdtree
  152. let g:NERDTreeWinSize = 25 "设定 NERDTree 视窗大小
  153. let NERDTreeShowBookmarks=1 " 开启Nerdtree时自动显示Bookmarks
  154. "打开vim时如果没有文件自动打开NERDTree
  155. " autocmd vimenter * if !argc()|NERDTree|endif
  156. "NERDTree为剩下的唯一窗口时自动关闭
  157. autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
  158. " 设置树的显示图标
  159. let g:NERDTreeDirArrowExpandable = '+'
  160. let g:NERDTreeDirArrowCollapsible = '-'
  161. let NERDTreeIgnore = ['\.pyc$'] " 过滤所有.pyc文件不显示
  162. let g:NERDTreeShowLineNumbers=0 " 是否显示行号
  163. let g:NERDTreeHidden=0 "不显示隐藏文件
  164. ""Making it prettier
  165. let NERDTreeMinimalUI = 1
  166. let NERDTreeDirArrows = 1
  167. nnoremap <F3> :NERDTreeToggle<CR> " 开启/关闭nerdtree快捷键
  168. " if hidden is not set, TextEdit might fail.
  169. set hidden
  170. " Some servers have issues with backup files, see #649
  171. set nobackup
  172. set nowritebackup
  173. " You will have bad experience for diagnostic messages when it's default 4000.
  174. set updatetime=300
  175. " don't give |ins-completion-menu| messages.
  176. set shortmess+=c
  177. " always show signcolumns
  178. set signcolumn=yes
  179. " Use tab for trigger completion with characters ahead and navigate.
  180. " Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
  181. inoremap <silent><expr> <TAB>
  182. \ pumvisible() ? "\<C-n>" :
  183. \ <SID>check_back_space() ? "\<TAB>" :
  184. \ coc#refresh()
  185. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  186. function! s:check_back_space() abort
  187. let col = col('.') - 1
  188. return !col || getline('.')[col - 1] =~# '\s'
  189. endfunction
  190. " Use <c-space> to trigger completion.
  191. inoremap <silent><expr> <c-space> coc#refresh()
  192. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
  193. " Coc only does snippet and additional edit on confirm.
  194. inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  195. " Or use `complete_info` if your vim support it, like:
  196. " inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
  197. " Use `[g` and `]g` to navigate diagnostics
  198. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  199. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  200. " Remap keys for gotos
  201. nmap <silent> gd <Plug>(coc-definition)
  202. nmap <silent> gy <Plug>(coc-type-definition)
  203. nmap <silent> gi <Plug>(coc-implementation)
  204. nmap <silent> gr <Plug>(coc-references)
  205. " Use K to show documentation in preview window
  206. nnoremap <silent> K :call <SID>show_documentation()<CR>
  207. function! s:show_documentation()
  208. if (index(['vim','help'], &filetype) >= 0)
  209. execute 'h '.expand('<cword>')
  210. else
  211. call CocAction('doHover')
  212. endif
  213. endfunction
  214. " Highlight symbol under cursor on CursorHold
  215. " autocmd CursorHold * silent call CocActionAsync('highlight')
  216. " Remap for rename current word
  217. nmap <leader>rn <Plug>(coc-rename)
  218. " Remap for format selected region
  219. xmap <leader>f <Plug>(coc-format-selected)
  220. nmap <leader>f <Plug>(coc-format-selected)
  221. augroup mygroup
  222. autocmd!
  223. " Setup formatexpr specified filetype(s).
  224. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  225. " Update signature help on jump placeholder
  226. " autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  227. augroup end
  228. " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
  229. xmap <leader>a <Plug>(coc-codeaction-selected)
  230. nmap <leader>a <Plug>(coc-codeaction-selected)
  231. " Remap for do codeAction of current line
  232. nmap <leader>ac <Plug>(coc-codeaction)
  233. " Fix autofix problem of current line
  234. nmap <leader>qf <Plug>(coc-fix-current)
  235. " Create mappings for function text object, requires document symbols feature of languageserver.
  236. xmap if <Plug>(coc-funcobj-i)
  237. xmap af <Plug>(coc-funcobj-a)
  238. omap if <Plug>(coc-funcobj-i)
  239. omap af <Plug>(coc-funcobj-a)
  240. " Use `:Format` to format current buffer
  241. command! -nargs=0 Format :call CocAction('format')
  242. " Use `:Fold` to fold current buffer
  243. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  244. " use `:OR` for organize import of current buffer
  245. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  246. filetype plugin on
  247. " 设置为双字宽显示,否则无法完整显示如:☆
  248. " set ambiwidth=double
  249. set t_ut= " 防止vim背景颜色错误
  250. set showmatch " 高亮匹配括号
  251. set matchtime=1
  252. set report=0
  253. set ignorecase
  254. set nocompatible
  255. set noeb
  256. set softtabstop=4
  257. set shiftwidth=4
  258. set nobackup
  259. set autoread
  260. set nocompatible
  261. set nu "设置显示行号
  262. set backspace=2 "能使用backspace回删
  263. syntax on "语法检测
  264. set ruler "显示最后一行的状态
  265. set laststatus=2 "两行状态行+一行命令行
  266. set ts=4
  267. set expandtab
  268. set autoindent "设置c语言自动对齐
  269. set t_Co=256 "指定配色方案为256
  270. " set mouse=a "设置可以在VIM使用鼠标
  271. set selection=exclusive
  272. " set selectmode=mouse,key
  273. set tabstop=4 "设置TAB宽度
  274. set history=1000 "设置历史记录条数
  275. " 配色方案
  276. " let g:seoul256_background = 234
  277. colo monokai
  278. set background=dark
  279. set shortmess=atl
  280. " colorscheme desert
  281. "共享剪切板
  282. set clipboard+=unnamed
  283. set cmdheight=3
  284. if version >= 603
  285. set helplang=cn
  286. set encoding=utf-8
  287. endif
  288. set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
  289. set termencoding=utf-8
  290. set encoding=utf-8
  291. set fileencodings=ucs-bom,utf-8,cp936
  292. set fileencoding=utf-8
  293. set updatetime=300
  294. set shortmess+=c
  295. set signcolumn=yes
  296. " autocmd FileType json syntax match Comment +\/\/.\+$+
  297. set foldmethod=indent " 设置默认折叠方式为缩进
  298. set foldlevelstart=99 " 每次打开文件时关闭折叠
  299. " hi Normal ctermfg=252 ctermbg=none "背景透明
  300. " au FileType gitcommit,gitrebase let g:gutentags_enabled=0
  301. if has("autocmd")
  302. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  303. endif
  304. inoremap jj <Esc> "将jj映射到Esc

打开一个 nvim 窗口,输入 :PlugInstall。安装完成后,输入 :checkhealth

3. 安装Coc插件

除此之外,我们还需要安装 Coc 相关插件,打开一个 Nvim 窗口,执行下面代码:

  1. :CocInstall coc-clangd coc-cmake coc-emmet coc-git coc-highlight coc-pairs
  2. :CocInstall coc-jedi coc-json coc-sh coc-snippets coc-vimlsp coc-yaml coc-syntax

参考文档:https://www.cnblogs.com/cniwoq/p/13272746.html
报错:https://www.cnblogs.com/sober-orange/p/cocnvim-build-indexjs.html

4. 常见报错

🔎报错:Unknown function: SemshiBufWipeout
解决办法:执行 :UpdateRemotePlugins,可以看见具体报错。

🔎报错:No module named pynvim
解决办法:原因在于当前 Python 环境下没有安装 pynvim 库。