vim coc.nvim安装及配置c,c++补全
在安装之前需要安装npm
yarn
node.js
# 这里以ubuntu示例
sudo apt install clang # 如果是c,c++补全需要安装
# 安装npm
sudo apt-get install npm
# 安装yarn
sudo npm install -g yarn
# 安装升级node.js到最新版本
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
node -v
Vundle
添加下面的内容到.vimrc
:
Plugin 'neoclide/coc.nvim'
VimPlug
添加下面的内容到.vimrc
:
Plug 'neoclide/coc.nvim'
在Vim
里面运行以下命令:
:source %
:PlugInstall
等待成功安装
在Vim
里面运行以下命令:
:CocInstall coc-clangd
# CocInstall coc-pyright 是python的
等待成功安装即可
可能遇到的问题
提示vim/nvim版本过低
# 更新vim版本
sudo add-apt-repository ppa:jonathonf/vim
sudo apt update
sudo apt upgrade
# 更新nvim版本
sudo apt-add-repository ppa:neovim-ppa/stable
sudo apt update
sudo apt install neovim
或者是
[coc.nvim] build/index.js not found, please install dependencies and compile coc.nvim by: yarn install
# 解决办法
# ~/.vim/bundle/coc.nvim/ #是我的coc.nvim插件的安装目录
cd ~/.vim/bundle/coc.nvim/
yarn install
yarn build
或者是
yarn install
时候报错,提示不存在这个文件或者目录
# 解决办法 尝试一下,再yarn install
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
这里贴一下我的配置
" CocUninstall 删除插件
" CocList extensions 列出扩展
" Cocinstall 安装插件
let g:coc_global_extensions = [
\'coc-vimlsp',
\'coc-clangd',
\'coc-pyright',
\'coc-word',
\'coc-snippets']
set pumheight=10 " 显示最大补全
set signcolumn=no " 取消左边报错提醒
highlight CocErrorLine cterm=undercurl ctermfg=Red " 将错误提醒改为 红线
" 使用CocConfig
function! SetupCommandAbbrs(from, to)
exec 'cnoreabbrev <expr> '.a:from
\ .' ((getcmdtype() ==# ":" && getcmdline() ==# "'.a:from.'")'
\ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfunction
call SetupCommandAbbrs('C', 'CocConfig')
" 设置回车补全
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" GoTo code navigation.
" 定义跳转
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)
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap for format selected region
xmap <leader>fm <Plug>(coc-format-selected)
nmap <leader>fm <Plug>(coc-format-selected)
" 跳转到帮助文档
nnoremap <silent> <LEADER>h :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" set signcolumn=yes
set updatetime=300
autocmd CursorHold * silent call CocActionAsync('highlight')
" 代码片段 参考 https://blog.csdn.net/niuiic/article/details/117599130
" CocCommand snippets.editSnippets 创建默认代码片段不推荐,推荐自定义位置
" CocCommand snippets.openSnippetFiles 打开代码片段文件
参考文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具