Vim(Neovim)配置coc.nvim

云利
2023-12-01

操作系统:Ubuntu20.40

安装coc

安装Node.js

  • 安装命令:curl -sL install-node.now.sh | bash
  • npm安装neovimyarnsudo 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',
    		\]
    

配置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
}

注:

 类似资料: