如果常用vim
的程序员的话,coc
这个插件即使没用过也听说过,这真是个强到没边的插件。
之所以写这个文件是因为用了一段coc
发现真是个强大的插件,可以对每次项功能做到非常精细的配置。
自己在用的过程中每一项都一点一点验证,把这个过程记录下来,可能会有很多朋友能用的上。
编辑CocConfig的方式有两种:
1.在vim输入: :CocConfig
,保存后生成文件
2.编辑文件,默认不存在该文件:
~/.config/nvim/coc-settings.json
完整配置,下面标逐渐分析每个配置的说明,每个配置都是在使用中,一点一点验证。
{
"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.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.detailMaxLength | 最大详情长度 | |
suggest.noselect | 补全自动选中第一个,很有用! | false |
suggest.enablePreselect | 关掉预选第一个,这个不关,按tab就会选中第二个 | true |
suggest.enablePreselect
相关问题: https://github.com/neoclide/coc.nvim/issues/1339
coc官方文档: https://github.com/neoclide/coc.nvim/blob/master/doc/coc.txt