Neovim开发环境搭建(2021.07.01)
Neovim开发环境搭建(2021.07.01)
一、搭建环境
- Ubuntu 21.04
- Neovim 0.4.4
二、Neovim安装
# 下载 neovim,如遇网络问题可以采用 https://hub.fastgit.org 镜像进行加速下载
# curl -LO https://hub.fastgit.org/neovim/neovim/releases/latest/download/nvim.appimage
$ curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage# 为 neovim 添加执行权限
$ chmod +x nvim.appimage# 将 neovim 移至 /usr/local/bin 目录下,并重命名为 nvim
$ sudo mv nvim.appimage /usr/local/bin/nvim# 测试 neovim 使用
$ nvim# 配置 vim 和 vi 使用 nvim(可选)
# 为 vi 和 vim 添加 nvim 可选项
$ sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/nvim 30
$ sudo update-alternatives --install /usr/bin/vim vim /usr/local/bin/nvim 30
# 配置 vi 和 vim 使用 nvim,选择列表中 nvim 对应的序号即可
$ sudo update-alternatives --config vi
$ sudo update-alternatives --config vim
三、vim-plug安装
vim-plug
是一个极简的 vim 插件管理工具,通过它我们可以非常方便的安装插件。
3.1 安装
3.1.1 Vim
# 使用 vim 的安装方式,如遇网络问题可以采用 https://raw.fastgit.org 镜像加速下载
# curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
# https://raw.fastgit.org/junegunn/vim-plug/master/plug.vim
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
3.1.2 Neovim
# 使用 neovim 的安装方式,如遇网络问题可以采用 https://raw.fastgit.org 镜像加速下载
# sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
# https://raw.fastgit.org/junegunn/vim-plug/master/plug.vim'
$ sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
3.3 使用
添加vim-plug
的配置到neovim
的配置文件~/.config/nvim/init.vim
中(vim
配置文件路径为~/.vimrc
)。
- 以
call plug#begin('~/.vim/plugged')
开始; - 用
Plug
命令列出所有需要安装插件; - 以
call plug#end()
结束;
示例:
" ~/.vim/plugged 为插件保存的路径,可自定义
call plug#begin('~/.vim/plugged')" 用 Plug 命令列出所有需要安装的插件
Plug 'jiangmiao/auto-pairs' " 自动补全括号插件
Plug 'neoclide/coc.nvim', {'branch': 'release'} " lsp语言服务协议" 结束
call plug#end()
重新加载配置文件通过:PlugInstall
命令来安装插件。
四、开发环境搭建
4.1 coc.nvim
4.1.1 安装
coc.nvim
扩展使neovim
(或者vim
)支持各种语言服务协议,从而实现智能提示等功能。
采用vim-plug
的方式进行安装,在.vimrc
或者init.vim
文件中添加以下内容:
Plug 'neoclide/coc.nvim', {'branch': 'release'}
重新加载配置文件通过:PlugInstall
命令来安装插件。
注:coc.nvim 需要依赖 node, 关于 node 的安装请自行查阅,此处不再赘述。
4.1.2 配置
coc.nvim
的配置较为复杂,此处采用默认配置,如有需求可以自行修改。
在.vimrc
或者init.vim
添加以下配置,以使 coc.nvim
更好的工作:
" Set internal encoding of vim, not needed on neovim, since coc.nvim using some
" unicode characters in the file autoload/float.vim
set encoding=utf-8" TextEdit might fail if hidden is not set.
set hidden" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup" Give more space for displaying messages.
set cmdheight=2" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300" Don't pass messages to |ins-completion-menu|.
set shortmess+=c" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")" Recently vim can merge signcolumn and number column into oneset signcolumn=number
elseset signcolumn=yes
endif" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>\ pumvisible() ? "\<C-n>" :\ <SID>check_back_space() ? "\<TAB>" :\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"function! s:check_back_space() abortlet col = col('.') - 1return !col || getline('.')[col - 1] =~# '\s'
endfunction" Use <c-space> to trigger completion.
if has('nvim')inoremap <silent><expr> <c-space> coc#refresh()
elseinoremap <silent><expr> <c-@> coc#refresh()
endif" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>function! s:show_documentation()if (index(['vim','help'], &filetype) >= 0)execute 'h '.expand('<cword>')elseif (coc#rpc#ready())call CocActionAsync('doHover')elseexecute '!' . &keywordprg . " " . expand('<cword>')endif
endfunction" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)augroup mygroupautocmd!" Setup formatexpr specified filetype(s).autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')" Update signature help on jump placeholder.autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
4.2 Python补全支持
coc.pyright
为coc.nvim
的一个插件,通过它可以实现python
语言的智能提示等。
通过以下命令安装扩展;
:CocInstall coc-pyright
配置
python
开发环境(如果已经配置跳过此步);打开
.py
文件即可自动识别实现提示补全等功能;
4.2 Java补全支持
coc-java
为coc.nvim
的一款插件,通过它可以实现java
语言的智能提示等。
通过以下命令安装扩展;
:CocInstall coc-java
安装 JDK 并正确配置环境变量(如果已经配置跳过此步);
打开
.java
文件将会自动激活;
注1:当没有发现 jdt.ls 时,该扩展会自动进行下载。
注2:如果
jdt
下载较慢,可以手动下载 jdt 并解包到coc-java
的数据文件夹下,可以在neovim
(或者vim
)中通过:echo coc#util#extension_root().'/coc-java-data/server'
命令获取文件路径。
五、其它扩展
5.1 coc.nvim
5.1.1 coc-json
:CocInstall coc-json
5.1.2 coc-sh
:CocInstall coc-sh
5.2 auto-pairs
Plug 'jiangmiao/auto-pairs'
5.3 rawbow
Plug 'luochen1990/rainbow'
let g:rainbow_active = 1 " 激活rainbow
5.4 vim-startify
Plug 'mhinz/vim-startify'
5.5 vim-airline
Plug 'vim-airline/vim-airline'
let g:airline_theme = 'nord' " 设置airline使用的主题
let g:airline_powerline_fonts = 1 " 使airline正常显示箭头" 设置 neovim 或者 vim 的 tabline
let g:airline#extensions#coc#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#tab_nr_type = 1
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#formatter = 'default'
let g:airline#extensions#tabline#buffer_nr_show = 0
let g:airline#extensions#tabline#fnametruncate = 16
let g:airline#extensions#tabline#fnamecollapse = 2
let g:airline#extensions#tabline#buffer_idx_mode = 1
5.6 vim-airline-themes
Plug 'vim-airline/vim-airline-themes'
5.7 nord-vim
Plug 'arcticicestudio/nord-vim'
5.8 gruvbox
Plug 'morhetz/gruvbox'
5.9 indentLine
Plug 'Yggdroot/indentLine'
5.10 nerdcommenter
Plug 'preservim/nerdcommenter'
let g:NERDSpaceDelims = 1 " 设置在注释分隔符后添加空格
let g:NERDCompactSexyComs = 1 " 设置多行使用简洁语法注释
let g:NERDTrimTrailingWhitespace = 1 " 设置允许注释清理行尾的空格
5.11 tabular
Plug 'godlygeek/tabular'
5.12 vim-gitgutter
Plug 'airblade/vim-gitgutter'
5.13 neoformat
Plug 'sbdchd/neoformat'
5.14 nerdtree
Plug 'preservim/nerdtree'
5.15 sonokai
Plug 'sainnhe/sonokai'
5.16 codi.vim
实时显示python
脚本执行结果,vim-plug
方式安装:
Plug 'metakirby5/codi.vim'
5.17 vim-pydocstring
Plug 'heavenshell/vim-pydocstring'
let g:pydocstring_doq_path = '~/.local/share/virtualenvs/python3.8/bin/doq' " pydocstring依赖doq的路径
5.18 tagbar
Plug 'preservim/tagbar'
let g:tagbar_ctags_bin = '/usr/bin/ctags' " tagbar依赖ctags的路径
5.19 vimspector
类似vscode
布局的 GUI 调试扩展,vim-plug
方式安装:
Plug 'puremourning/vimspector'
let g:vimspector_enable_mappings = 'VISUAL_STUDIO' " vimspector快捷键方案
5.20 vim-easycomplete
自动补全扩展,功能类似coc.nvim
,vim-plug
方式安装:
Plug 'jayli/vim-easycomplete'
5.21 ultisnips
Plug 'SirVer/ultisnips'
5.22 vim-snippets
Plug 'honza/vim-snippets'
六、其它配置
set relativenumber " 设置显示相对行号
set number " 设置显示行号
set expandtab " 设置TAB使用空格
set tabstop=4 " 设置TAB缩进的空格数量
set shiftwidth=4 " 自动缩进的宽度
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 " 解决中文乱码
set termencoding=utf-8
set encoding=utf-8" 插入模式键映射
inoremap kk <Esc>" 普通模式键映射
" 打开文件树
nnoremap <leader>e :CocCommand explorer<CR>
" 保存
nnoremap <leader>w :w<CR>
" 删除buffer
nnoremap <leader>bd :bd<CR>
" 下一个buffer
nnoremap <leader>bn :bn<CR>
" 上一个buffer
nnoremap <leader>bp :bp<CR>
" 关闭tab
nnoremap <leader>tc :tabclose<CR>
Neovim开发环境搭建(2021.07.01)相关推荐
- 【Flutter】Flutter 开发环境搭建 ( 2021年08月25日 补充最新资料 | 最新安装教程 )
文章目录 前言 一.Android Studio 环境安装 Flutter / Dart 插件 二.Flutter SDK 下载 三.设置 Flutter 环境变量 1.设置 Flutter SDK环 ...
- 微信公众号Java开发-笔记01【微信公众号介绍、开发环境搭建】
学习网址:哔哩哔哩网站 微信公众号开发-Java版 微信公众号Java开发-笔记01[微信公众号介绍.开发环境搭建] 微信公众号Java开发-笔记02[] 微信公众号Java开发-笔记03[] 微信公 ...
- ESP32 入门笔记01:乐鑫ESP32-DevKitC开发板信息、开发环境搭建以及学资料准备
文章目录 一.ESP32-DevKitC 开发板介绍 二.ESP32 开发环境 1. Arduino IDE 1.1 开发环境搭建步骤 1.2 实验:使用 Arduino IDE 将代码上传到 ESP ...
- stm32f4 hal 4位数码管_STM32裸机开发基础篇01开发环境搭建(HAL库)
前言 众所周知,在32位单片机中,STM32占有重要市场份额,其社区活动频繁,网上相关资料也比较多,无论是学习入门,还是工作使用,都无疑是极好的选择,本节开始,我们将学习如何使用STM32,首先,我们 ...
- 01 esp32c3 Arduino 开发环境搭建
参考链接 参考链接2 离线安装 esp32 Arduino 下载 Arduino ide 并安装 打开[文件]->[首选项]->[附件开发板管理器网址]填入一下网址: https://ww ...
- 【从零开始人工智能01】人工智能运行开发环境搭建
从零开始人工智能系列: 人工智能运行开发环境搭建 第一个人工智能小程序:强化学习找金币 人工智能运行开发环境搭建 一.系统要求 操作系统为Win10.如果有条件的话,建议还是在Linux系统下搭建人工 ...
- 【Android基础笔记01】Android开发环境搭建和HelloWorld
最近手头项目3.0版本要上线了, 没有那么多工作压力了, 抽空看了看之前在云笔记上做的笔记 都是一些基础知识 给大家分享出来吧 一.什么是Android?[了解 ] Android(中文俗称安卓)是一 ...
- Golang开发环境搭建-Vim篇
Golang开发环境搭建-Vim篇 转自:http://tonybai.com/2014/11/07/golang-development-environment-for-vim/ 虽说sublime ...
- 【OpenStack】OpenStack系列1之OpenStack本地开发环境搭建向社区贡献代码
加入OpenStack社区 https://launchpad.net/,注册用户(597092663@qq.com/Admin@123) 修改个人信息,配置SSH keys.OpenPGP keys ...
最新文章
- 向sqlce 里插入和取出一个Image
- 21.使用委托表达回调
- oracle as 不可以省略,Oracle:存储过程,存储函数
- Linux shell条件判断
- 以串结构存储c语言版,数据结构C语言版 串的块链存储表示和实现
- Struts知识问答
- 如何为报表服务器设置SQL Server数据库复制
- Silverlight .xap文件详解
- 谷歌浏览器启动页被篡改为hao.7654.com的解决办法
- Outlook2013 邮件签名设置
- 8个设计师必看的免费UI图标设计资源站
- 定制Hexo-NexT的个性化博客
- 轻量级任务调度中间件
- 电脑 清理android,怎样清除系统垃圾 手机电脑一举拿下【图文】
- python程序怎么给别人运行_如何把自己写的python程序给别人用
- Java learn lambda的方法引用
- 东芝计算机配置,东芝z830配置 东芝Z830-K02S参数【图文】
- 旷视深度学习框架MegEngine开源
- 中触媒科创板上市:市值74亿 为李进与刘颐静夫妻店
- eclipse c语言 自动补全,eclipse里头怎么设C/C++的智能提示