vim配置——c++代码自动补全

O 简介

自己配置vim主要分为两大部分:一个是通过set设置vim的属性;另一个是插件下载

一 、插件管理器及clangd代码补全

vim插件管理器与其他软件包管理器如yum, apt, 以及python中的pip等相同,都为软件包管理器,vim的软件包管理器又称插件管理器,常见的vim插件管理器有:

  • vim-plug junegunn/vim-plug: Minimalist Vim Plugin Manager (github.com)
  • VundleVim : VundleVim/Vundle.vim: Vundle, the plug-in manager for Vim (github.com)

本文安装的是vim-plug,操作系统是WSL Ubuntu20.04

1. vim-plug安装

GitHub的项目给出了两种方法,一种是在命令行直接下载,另一种是在vim的配置文件.vimrc中下载

在命令行直接下载的方法:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

需要注意的是:raw.githubusercontent.com 可能会访问不到,参考连接:彻底解决【“curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused”】错误_donaldsy的技术博客_51CTO博客

需要修改一下网络的配置文件,修改方法为在/etc/hosts文件里添加raw.githubusercontent.com的ip地址

网站ip地址的查询网站:The Best IP Address, Email and Networking Tools - IPAddress.com

2. 通过vim-plug下载vim插件

在.vimrc中增加要下载的插件名或插件地址,默认地址为github,

以call plug#begin()开头

中间为要下载的插件

最后以call plug#end()结尾

call plug#begin()
" The default plugin directory will be as follows:
"   - Vim (Linux/macOS): '~/.vim/plugged'
"   - Vim (Windows): '~/vimfiles/plugged'
"   - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
"   - e.g. `call plug#begin('~/.vim/plugged')`
"   - Avoid using standard Vim directory names like 'plugin'" Make sure you use single quotes" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }" Using a non-default branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'" Initialize plugin system
" - Automatically executes `filetype plugin indent on` and `syntax enable`.
call plug#end()
" You can revert the settings after the call like so:
"   filetype indent off   " Disable file-type-specific indentation
"   syntax off            " Disable syntax highlighting

代码自动填充的插件为:

github地址:neoclide/coc.nvim: Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers. (github.com)

" Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}" Or build from source code by using yarn: https://yarnpkg.com
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'}

.vimrc书写完成后,在vim中执行PlugInstall

然后再利用coc安装coc的扩展

:CocInstall clangd   //表示为c++的代码自动补全

3. vim升级至8.2

(5条消息) linux ubuntu如何装vim,Ubuntu 18.04/20.04下安装Vim 8.2_孔李聃丘的博客-CSDN博客

sudo add-apt-repository ppa:jonathonf/vimsudo apt-get updatesudo apt install vim

4. 升级Nodejs

(5条消息) 升级Ubuntu nodejs 版本_放大的EZ的博客-CSDN博客

安装npm

安装n

升级nodejs

sudo apt-get install  npm
sudo npm install n -g
sudo n stable

5. 安装自动补全扩展

在vim的命令行

CosInsatll coc-clangd

回到命令行安装: 为什么??? 我不理解,但是不安装的话每个vim文件里都要CosInsatll coc-clangd才能提醒

vim-plug+coc.nvim实现vim C/C++自动补全 - 知乎 (zhihu.com)

sudo apt-get install clangd

知道了,没有设置路径

export PATH=$PATH:/home.config/coc/extensions/node_modules/coc-clangd

不知道sudo apt-get install clangd是不是必须要安装的,和CocInstall coc-clangd区别??

答:sudo apt install clangd安装后的clangd在/usr/bin里面有可执行文件
而在vim中使用:CocInstall coc-clangd安装后可执行文件在/usr/lib/llvm-10/bin/clangd
使用软连接解决该问题

sudo ln -s /usr/lib/llvm-10/bin/clangd /usr/bin/clangd

6. 配置.vimrc

上面的步骤执行完成后,出现了代码提示的功能,但是无论回车或者空格都没有自动补全的效果

将coc项目中的.vimrc配置复制,实现了补全功能

" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file.
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>\ coc#pum#visible() ? coc#pum#next(1):\ CheckBackspace() ? "\<Tab>" :\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"function! CheckBackspace() abortlet col = col('.') - 1return !col || getline('.')[col - 1]  =~# '\s'
endfunction" Use <c-space> to trigger completion.
if has('nvim')inoremap <silent><expr> <c-space> coc#refresh()
elseinoremap <silent><expr> <c-@> coc#refresh()
endif" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)" 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)" Use K to show documentation in preview window.
nnoremap <silent> K :call ShowDocumentation()<CR>function! ShowDocumentation()if CocAction('hasProvider', 'hover')call CocActionAsync('doHover')elsecall feedkeys('K', 'in')endif
endfunction" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)" Formatting selected code.
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)augroup mygroupautocmd!" Setup formatexpr specified filetype(s).autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')" Update signature help on jump placeholder.autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac  <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf  <Plug>(coc-fix-current)" Run the Code Lens action on the current line.
nmap <leader>cl  <Plug>(coc-codelens-action)" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call     CocAction('fold', <f-args>)" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>

ait> s :CocList -I symbols
" Do default action for next item.
nnoremap j :CocNext
" Do default action for previous item.
nnoremap k :CocPrev
" Resume latest coc list.
nnoremap p :CocListResume


vim配置——C/C++代码自动补全相关推荐

  1. Pydiction : VIM上的PYTHON代码自动补全插件

    http://www.vim.org/scripts/script.php?script_id=850 1.下载Pydiction 其中有4个文件: complete-dict //PYTHON 的K ...

  2. 【vim环境配置】解决ubuntu上 由YouCompleteMe插件配置不当引起的 自动补全失效的问题

    [vim环境配置]解决ubuntu上 由YouCompleteMe插件配置不当引起的 自动补全失效的问题 参考文章: (1)[vim环境配置]解决ubuntu上 由YouCompleteMe插件配置不 ...

  3. python jupyter notebook怎么调字体大小_配置Jupyter的代码主题 字体以及字体大小 代码自动补全...

    jupyter默认没有代码提示,字体非常的难看,特别是引号,一直想更换字体和主题,就把方法整理了一下.如果你单独想更换字体的话,需要修改浏览器的字体,这个是受浏览器的影响. 如果想更换主题往下看,代码 ...

  4. 组织管理插件-代码自动补全-语法检查等特性-SpaceVim v1.5.0

    简介: SpaceVim 是一个社区驱动的模块化 Vim/Neovim 配置集合,以模块的方式组织管理插件以 及相关配置,为不同的语言开发量身定制了相关的开发模块,该模块提供代码自动补全, 语法检查. ...

  5. python代码自动补全利器----Kite介绍安装使用教程

    目录 Kite介绍 Kite安装 总结 介绍一款针对python代码自动补全的工具 -- Kite ,不需额外的环境配置,more importantly是免费的哦~~对于经常使用Python的朋友们 ...

  6. vs代码补全的快捷键_效率工具 | 一款基于深度学习的代码自动补全神器

    前言 代码补全对于大多数开发人员来说是至关重要的,它可以有效的提高开发效率.减少拼写错误和输入代码量.我们使用的大多数开发工具都自带补全功能,或者可以通过安装插件具备补全功能.但是,以往的代码补全功能 ...

  7. dev c++代码自动补全_让代码自动补全的全套流程

    作者: 熊唯,黄飞 ,腾讯 PCG/QQ研发中心/CV应用研究组 AI 如果真的可以写代码了,程序员将何去何从?近几年,NLP 领域的生成式任务有明显的提升,那通过 AI 我们可以让代码自动完成后续补 ...

  8. 让代码自动补全的全套流程

    作者:熊唯,黄飞 ,腾讯 PCG/QQ研发中心/CV应用研究组 AI 如果真的可以写代码了,程序员将何去何从?近几年,NLP 领域的生成式任务有明显的提升,那通过 AI 我们可以让代码自动完成后续补全 ...

  9. emacs c语言 自动补全,Emacs 与 C/C++ 代码自动补全

    基于 Emacs 的 company 模式并配合 semantic 文法分析器,实现 Emacs 的 C/C++ 代码自动补全. 关于 Emacs 的代码自动补全 代码自动补全的功能,对于使用 Ema ...

  10. 这个 Python 代码自动补全神器搞得我卧槽卧槽的

    是时候跟你说说这个能让你撸代码撸得舒服得不要不要的神器了--kite. ​! 简单来说,它是一款 IDE 的插件,能做到代码自动补全,可能你会说了,这有什么牛逼的?一般的编辑器不都有这个功能么? 它虽 ...

最新文章

  1. OpenCV 【十三】矩阵的掩码操作
  2. 单片机有什么好的网课?
  3. 面试官:会玩牌吧?给我讲讲洗牌算法和它的应用场景吧!
  4. 硬不硬你说了算!近 40 张图解被问千百遍的 TCP 三次握手和四次挥手面试题
  5. MPEG2-TS音视频同步原理
  6. 类WebOS(添加了主界面,及相关功能代码)
  7. js中继承的几种用法总结(apply,call,prototype)
  8. python中可变参数和关键字参数_python的可变参数和关键字参数(*args **kw)
  9. Navicat 远程连接docker容器中的mysql 报错1251 - Client does not support authentication protocol 解决办法
  10. 敏捷项目计划的多层面
  11. java与java ee_Java EE MVC:处理表单验证
  12. 【数据结构与算法】顺序栈的Java实现
  13. linux===Ubuntu修改设备名称
  14. JavaScript之定义函数的方法
  15. python源码剖析笔记
  16. SQL 常见面试题解析
  17. Shell脚本学习-阶段二十七-命令解释二
  18. 头歌-信息安全技术-【实训10】HTML信息隐藏、动态分析技术
  19. 七、python基础:格式化占位符
  20. ContentProvider介绍

热门文章

  1. 15 使用计算机应遵守行业道德规范,初中信息技术会考试题 -
  2. 基于egret的点光源光线效果的实现
  3. python生成列表a到z_python实现 1-26=A-Z, then AA-AZ, BA-BZ...ZZA-ZZZ, AAAA, etc.
  4. 网易邮箱大师添加附件显示服务器连接失败,网易邮箱大师如何添加Word附件 添加附件方法步骤详细介绍...
  5. 春节红包战:他们到底在争什么?
  6. Jinja2 入门教程、基本概念、简单使用及使用 Jinja2 生成 H3C 交换机配置举例
  7. Google map根据经纬度获取地址信息
  8. 创业公司必备,20个提升团队工作效率的工具神器
  9. zigbee学习之JN5169 串口UARTs
  10. 深度学习-自然语言处理(NLP)-第三方库(工具包):Synonyms【更好的中文近义词、聊天机器人、智能问答工具包】