前言

如果常用vim的程序员的话,coc 这个插件即使没用过也听说过,这真是个强到没边的插件。
之所以写这个文件是因为用了一段coc发现真是个强大的插件,可以对每次项功能做到非常精细的配置。
自己在用的过程中每一项都一点一点验证,把这个过程记录下来,可能会有很多朋友能用的上。

CocConfig

编辑CocConfig的方式有两种:

1.在vim输入: :CocConfig,保存后生成文件
2.编辑文件,默认不存在该文件:

~/.config/nvim/coc-settings.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
{
"coc.preferences.semanticTokensHighlights": false,
"coc.preferences.enableFloatHighlight": true,
"coc.preferences.snippetStatusText": "Ⓢ ",
"coc.preferences.extensionUpdateCheck": "daily",
"coc.preferences.messageLevel": "error",
"coc.source.around.firstMatch": false,
"coc.source.buffer.firstMatch": false,
"coc.source.syntax.firstMatch": false,
"suggest.detailMaxLength": 60,
"suggest.noselect": true,
"suggest.enablePreselect": false,
"suggest.triggerAfterInsertEnter": true,
"suggest.autoTrigger": "always",
"suggest.timeout": 5000,
"suggest.enablePreview": true,
"suggest.floatEnable": true,
"suggest.detailField": "preview",
"suggest.snippetIndicator": "",
"suggest.triggerCompletionWait": 100,
"suggest.echodocSupport": true,
"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.signOffset": 1,
"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": false,
"codeLens.enable": true,
"list.previewHighlightGroup": "Statement",
"list.nextKeymap": "<C-e>",
"list.previousKeymap": "<C-u>",
"importCost.bundleSizeDecoration": "both",
"importCost.typescriptExtensions": [
"\\.tsx?$"
],
"importCost.javascriptExtensions": [
"\\.jsx?$"
],
"importCost.showCalculatingDecoration": true,
"importCost.debug": false,
"snippets.ultisnips.directories": [
"$HOME/.config/nvim/Ultisnips/",
"$HOME/.config/nvim/plugged/vim-snippets/UltiSnips/"
],
"coc.preferences.formatOnSaveFiletypes": [
"javascript",
"typescript",
"html",
"css",
"json",
"java",
"python",
"vue",
"svelte",
"c",
"cs",
"prisma"
],
"yaml.format.enable": true,
"signature.target": "float",
"yank.enableCompletion": false,
"jest.watch": false,
"explorer.width": 38,
"explorer.quitOnOpen": true,
"explorer.sources": [
{
"name": "buffer",
"expand": false
},
{
"name": "file",
"expand": true
}
],
"explorer.file.column.indent.indentLine": true,
"explorer.file.showHiddenFiles": true,
"explorer.icon.enableNerdfont": true,
"explorer.file.column.git.showIgnored": true,
"explorer.keyMappingMode": "none",
"explorer.buffer.showHiddenBuffers": false,
"explorer.keyMappings.global": {
"u": "nodePrev",
"e": "nodeNext",
"h": "toggleSelection",
"<tab>": "actionMenu",
"gl": "expandRecursive",
"gh": "collapseRecursive",
"i": [
"wait",
"expandable?",
"expand",
"open"
],
"<cr>": [
"wait",
"expandable?",
"cd",
"open"
],
"I": "open:vsplit",
"o": [
"wait",
"expanded?",
"collapse",
"expand"
],
"O": "open:tab",
"n": "collapse",
"l": "gotoParent",
"yp": "copyFilepath",
"yn": "copyFilename",
"yy": "copyFile",
"dd": "cutFile",
"pp": "pasteFile",
"dD": "deleteForever",
"a": "addFile",
"k": "addFile",
"M": "addDirectory",
"cw": "rename",
".": "toggleHidden",
"zh": "toggleHidden",
"R": "refresh",
"?": "help",
"q": "quit",
"X": "systemExecute",
"gd": "listDrive",
"f": "search",
"F": "searchRecursive",
"B": "gotoSource:file",
"b": "gotoSource:buffer",
"[[": "sourcePrev",
"]]": "sourceNext",
"[d": "diagnosticPrev",
"]d": "diagnosticNext",
"[c": "gitPrev",
"]c": "gitNext",
"<<": "gitStage",
">>": "gitUnstage"
},
"tslint.autoFixOnSave": false,
"python.autoComplete.addBrackets": true,
"python.jediEnabled": false,
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
"--style",
"{SPACES_AROUND_POWER_OPERATOR: True, SPACES_BEFORE_COMMENT: 1}"
],
"html.format.enable": true,
"javascript.referencesCodeLens.enable": true,
"javascript.showUnused": true,
"javascript.suggest.names": true,
"javascript.suggestionActions.enabled": true,
"json.format.enable": true,
"eslint.autoFixOnSave": false,
"prettier.printWidth": 100,
"prettier.disableLanguages": [],
"prettier.formatterPriority": 1,
"prettier.useTabs": true,
"prettier.trailingComma": "all",
"prettier.singleQuote": false,
"todolist.autoUpload": true,
"todolist.promptForReminder": false,
"coc-actions.hideCursor": false,
"coc-actions.showActionKind": true,
"diagnostic-languageserver.filetypes": {
"vim": "vint",
"email": "languagetool",
"markdown": [
"write-good",
"markdownlint"
],
"sh": "shellcheck",
"elixir": [
"mix_credo",
"mix_credo_compile"
],
"eelixir": [
"mix_credo",
"mix_credo_compile"
],
"php": [
"phpstan",
"psalm"
]
},
"diagnostic-languageserver.formatFiletypes": {
"elixir": "mix_format",
"eelixir": "mix_format"
},
"languageserver": {
"lua": {
"command": "lua-lsp",
"filetypes": [
"lua"
]
},
"golang": {
"command": "gopls",
"rootPatterns": [
"go.mod"
],
"filetypes": [
"go"
],
"initializationOptions": {
"gocodeCompletionEnabled": true,
"diagnosticsEnabled": true,
"lintTool": "golint"
}
},
"bash": {
"command": "bash-language-server",
"args": [
"start"
],
"filetypes": [
"sh"
],
"ignoredRootPaths": []
},
"ccls": {
"command": "ccls",
"filetypes": [
"c",
"cpp",
"cuda",
"objc",
"objcpp"
],
"rootPatterns": [
".ccls",
".ccls-root",
"compile_commands.json",
".git/",
".hg/"
],
"initializationOptions": {
"cache": {
"directory": "/tmp/ccls"
}
}
}
},
"java.enabled": true,
"java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "/Users/liukai/workspaces/application/jdk-17.0.2.jdk/Contents/Home"
},
{
"name": "JavaSE-17",
"path": "/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home",
"default": true
}
],
"java.configuration.maven.userSettings": "/Users/liukai/.m2/settings.xml",
"java.import.gradle.enabled": true,
"java.jdt.ls.lombokSupport.enabled": false,
"java.jdt.ls.statusIcons": "ready",
"java.imports.gradle.wrapper.checksums": [
{
"sha256": "6246ebc8a7be938275282bf9c3ec79238e08e6b442d38a66633731ae8daffd5d",
"allowed": false
}
],
"java.import.gradle.home": "/Users/liukai/workspaces/application/gradle-6.6.1/bin",
"java.import.gradle.java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home",
"rust-analyzer.enable": true
}

coc 自身配置

参数名 作用 默认值
coc.preferences.semanticTokensHighlights
coc.preferences.enableFloatHighlight
coc.preferences.snippetStatusText
coc.preferences.extensionUpdateCheck
coc.preferences.messageLevel
coc.source.around.firstMatch
coc.source.buffer.firstMatch
coc.source.syntax.firstMatch

suggest 补全

参数名 作用 默认值
suggest.detailMaxLength 最大详情长度
suggest.noselect 补全自动选中第一个,很有用! false
suggest.enablePreselect 关掉预选第一个,这个不关,按tab就会选中第二个 true

suggest.enablePreselect相关问题: https://github.com/neoclide/coc.nvim/issues/1339

diagnostic

java

rust

go

json

参考链接

coc官方文档: https://github.com/neoclide/coc.nvim/blob/master/doc/coc.txt