操作系统:Ubuntu20.40
。
安装coc
安装Node.js
- 安装命令:
curl -sL install-node.now.sh | bash
npm
安装neovim
和yarn
:sudo npm i --registry https://registry.npm.taobao.org install -g neovim yarn
- 配置淘宝镜像:
npm config set registry https://registry.npm.taobao.org
vim-plug安装coc.nvim
- 在Vim默认配置文件或Neovim默认配置文件中添加:
Plug 'neoclide/coc.nvim', {'branch': 'release'}
- 先保存文件,比如vim用
:w
- vim命令模式加载配置文件:
:source %
- 安装插件:
PlugInstall
- 检查
coc.nvim
服务状态::checkhealth
coc常用命令
- 查看安装了那些子插件:
:CocList extensions
。可采用模糊搜索方法选中安装的插件,之后按Tab
对插件进行处理。 - 命令模式安装插件的命令:
:CocInstall
- 打开配置文件命令:
:CocConfig
安装coc扩展
- 安装
coc.nvim
子插件商城::CocInstall coc-marketplace
- 安装
markdown
子插件:- 使用
:coc-marketplace
查询插件::CocList marketplace markdown
- 安装
coc-markdownlint
::CocInstall coc-markdownlint
- 使用
- 通过
coc.nvim
提供的更方便的方式安装插件(推荐)- 在vim(neovim)配置文件里面设置变量:
g:coc_global_extensions
。 - 比如添加如下设置,再次进入vim时,就会自动安装列表里面的子插件。
let g:coc_global_extensions = [ \ 'coc-marketplace', \ 'coc-json', \ 'coc-vimlsp', \ 'coc-markdownlint', \ 'coc-sh', \ 'coc-pyright', \ 'coc-yaml', \ 'coc-tabnine', \ 'coc-translator', \ 'coc-snippets', \ 'coc-java', \ 'coc-java-intellicode', \ 'coc-xml', \]
- 在vim(neovim)配置文件里面设置变量:
配置coc.nvim的配置文件
- 打开
vim(nvim)
,命令模式下输入:CocConfig
进行配置。也可以编辑默认目录下的文件~/.config/nvim/coc-settings.json
。
{
"coc.preferences.extensionUpdateCheck": "daily",
"suggest.noselect": true,
"suggest.enablePreselect": false,
"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.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,
"codeLens.enable": true,
"list.previewHighlightGroup": "Statement",
// 保存时调整格式
"coc.preferences.formatOnSaveFiletypes": [
"javascript",
"typescript",
"html",
"css",
"json",
"java",
"python",
"vue",
"c",
"cpp",
"markdown",
"lua",
"bash"
],
"snippets.ultisnips.directories": [
"$HOME/.vim/plugged/vim-snippets/UltiSnips"
],
"coc.preferences.snippetStatusText": "Ⓢ ",
"python.formatting.provider": "black",
"java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "/usr/lib/jvm/java-17-openjdk-amd64"
},
{
"name": "JavaSE-1.8",
"path": "/usr/lib/jvm/jdk1.8.0_202/bin/java",
"default": true
}
],
"languageserver": {
"bash": {
"command": "bash-language-server",
"args": [
"start"
],
"filetypes": [
"sh"
]
}
},
"yaml.format.enable": true
}
注:
- 如果
java
遇到Error: The "java" server crashed xxx times in the last xxx minutes. The server will not be restarted
错误时,参看coc-java
的github上面提到的解决方法jdk版本与jdt语言服务器版本适配问题。