neovim的配置

当前neovim系列,neovim的配置

neovim的配置


neovim的配置文件夹

  • 前提,使用linux系统 或者wsl子系统red ,并且有足够版本的neovim
  • 一般来说,如果想要升级到最新的neovim,linux内核需要更新;一些发行版本是可以满足这个条件的。
1
2
mkdir ~/.config/nvim
nvim ~/.config/nvim/init.vim
  • 相较于vim,neovim的配置文件略有不同,同时,在home的用户下面创建新的neovim配置文件,会覆盖 原来的文件夹。

neovim的插件配置方法:vim-plug

  • 相较于传统的vundle,vim-plug现在还有人在进行维护,用它来管理vim插件较为方便。
  • vimplug插件可以在vimawesome中找到。

vim-plug的安装

  1. 首先安装前提,安装neovim,安装git,安装curl
1
2
sudo pacman -S neovim
sudo pacman -S git curl
  1. 进入github网站,下载vim-plug插件管理器
  2. 在github页面中,通过curl方法下载vim-plug:
1
2
curl -fLo ~/.var/app/io.neovim.nvim/data/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

vim-plug的使用方法

  • 进入vim配置文件中,neovim的配置文件夹 这一步骤中有明确的表述。
  • 使用我们新的neovim打开这个文件夹:
1
nvim ~/.config/nvim/init.vim
  • 在这个文件末尾添加:
1
2
3
4
5
call plug#begin()

Plug '你想要的vim插件'

call plug#end()
  • 安装完成之后保存,然后用neovim打开任意文档,使用: ,然后输入:
1
PlugInstall
  • 等待即可完成安装,但是如果网络不好,就絮要自己添加路径了。

coc.nvim配置

coc.nvim安装

  • coc是一个可以替代youcompleteme的补全插件,当然,如果你可以直接访问github,那么可以直接安装youcompleteme
  • coc.nvim 有自己的插件市场,他是一个可以安装自己的插件的插件,^-^有点套娃了,但是他确实很强大。
  • 安装方法,直接在neovim配置文件夹中使用vim-plug进行安装:
1
2
3
call plug#begin()
Plug 'neoclide/coc.nvim'
call plug#end()
  • 这一步安装完成之后,还需要进行配置你所需要的程序语言类型,才能为你提供相应的插件补全。
  • 安装方法:
1
:CocInstall coc-json

coc现存扩展

1
:CocList extensions
  • 通过这个命令可以查看已经安装的插件。
  • 查看是否存在某个函数:
1
:echo exists('*complete_info')

coc自身插件商店

1
:CocList marketplace

coc其他命令

  • coc自身本身的插件指令,这一部分可以直接查看coc官方文档。

coc扩展帮助

1
:h 插件名称

通过init.vim来管理coc.nvim

  • 直接对照官方文档,在init.vim中预留位置来进行配置。

coc-settings.json配置coc参数

官方的描述是这样的:The user configuration is named as coc-settings.json and placed inside
the folder $XDG_CONFIG_HOME/nvim or $HOME/.config/nvim by default (or
$HOME/.vim for vim). Run the command :CocConfig to open your user
configuration file.

  • 打开方式是:
1
nvim ~/.config/nvim/coc-setting.json

或者使用:

1
:CocConfig

coc-snippets


NerdTree

  • 关于NerdTree,在github中可以找到比较完善的介绍。
  • 我这里仅仅设置了使用F4进行设置打开和关闭。
  • 安装方法也是在vim-plug中进行安装。

目前配置

  • 最后是我当前的配置,有一些是关于主题设置,还有其他小插件,喜欢的可以直接拿去
  • 操作步骤在上一篇文章中有过解释。
  • 建议不要复制关于tab的一些操作,可以修改为其他按键,因为绑定以后就只能使用空格打制表符。

init.nvim

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
let g:loaded_perl_provider = 0

"use the jsonc as configure file for coc.nvim
autocmd FileType json syntax match Comment +\/\/.\+$+
"##########################################################
"##########################################################
call plug#begin()

"use the dart skim
Plug 'dart-lang/dart-vim-plugin'

"use the vim-snippets
Plug 'honza/vim-snippets'

"use the complete"[,(,{" and delete double
Plug 'jiangmiao/auto-pairs'
"use the theme tools
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"use the theme tools
Plug 'morhetz/gruvbox'
"use the completion tools
Plug 'neoclide/coc.nvim', {'branch': 'release'}

"use NerdTree
Plug 'preservim/nerdtree'
call plug#end()




"##########################################################
"use the theme
set bg=light
" colorscheme one
autocmd vimenter * ++nested colorscheme gruvbox
"###########################################################
"use vim-airline_theme
set laststatus=2 "永远显示状态栏
let g:airline_powerline_fonts = 1 " 支持 powerline 字体
let g:airline_solarized_bg='light'
" solarized light,other theme are in Screenshots,first
" use the :ArilineTheme solarized
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_left_sep = '▶'
let g:airline_left_alt_sep = '❯'
let g:airline_right_sep = '◀'
let g:airline_right_alt_sep = '❮'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
"###########################################################
"-------------------------------------------------------
"##########################################################
"use the auto-pairs
au Filetype FILETYPE let b:AutoPairs = {"(": ")"}
au FileType php let b:AutoPairs = AutoPairsDefine({'<?' : '?>', '<?php': '?>'})

"###########################################################
"
"use NerdTree
map <F4> :NERDTreeToggle<CR>
"###########################################################
"coc.nvim
"coc-vimlsp is a tool to use in vim,not_like
"other language
let g:coc_global_extensions = [
\'coc-rust-analyzer',
\'coc-rome',
\'coc-python',
\'coc-clangd',
\'coc-marketplace',
\'coc-vimlsp',
\'coc-json']

"set cache
set hidden

"set updatetime
set updatetime=100

"set merge signcolumn
set signcolumn=number

"set don't pass message to |ins-completion-menu|
set shortmess+=c
"set tab can do the completion
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() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
"set trigger can open the completion,only use in insert
inoremap <silent><expr> <c-l> coc#refresh()
"set enter to complete the completion
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" :"\<C-g>u\<CR>"

"use "g[" and "]g"check the error of code
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation.use gd to navigate and use ctrl+o back
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 "\"+h to find the document of functions
nnoremap <silent> <LEADER>h :call <SID>show_documentation()<CR>

"use rename fuction
nmap <leader>r <Plug>(coc-rename)

coc-setting.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{
"clangd.path": "~/.config/coc/extensions/coc-clangd-data/install/15.0.3/clangd_15.0.3/bin/clangd",
"coc.preferences.extensionUpdateCheck": "daily",
"suggest.noselect": true,
"suggest.enablePreselect": false,
"codeLens.enable": true,
"coc.preferences.formatOnSaveFiletypes": [
"json",
"rust-analyzer",
"rust",
"clangd"
],
"suggest.completionItemKindLabels": {
"class": "\uf0e8",
"color": "\ue22b",
"constant": "\uf8fe",
"default": "\uf29c",
"enum": "\uf435",
"enumMember": "\uf02b",
"event": "\ufacd",
"field": "\uf93d",
"file": "\uf723",
"folder": "\uf115",
"function": "\u0192",
"interface": "\uf417",
"keyword": "\uf1de",
"method": "\uf6a6",
"module": "\uf40d",
"operator": "\uf915",
"property": "\ue624",
"reference": "\ufa46",
"snippet": "\ue60b",
"struct": "\ufb44",
"text": "\ue612",
"typeParameter": "\uf728",
"unit": "\uf475",
"value": "\uf89f",
"variable": "\ue71b"
},
"diagnostic.errorSign": "\uf467",
"diagnostic.warningSign": "\uf071",
"diagnostic.infoSign": "\uf129",
"diagnostic.hintSign": "\uf864",
"diagnostic.displayByAle": false,
"diagnostic.refreshOnInsertMode": false,
"diagnostic.checkCurrentLine": true,
"diagnostic.virtualTextPrefix": " ❯❯❯ ",
"diagnostic.virtualText": true
}