Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 概念
  • 安装依赖软件和库
  • 下载 YouCompleteMe 源码
  • 编译 YouCompleteMe
  • 配置 YCM
  • vim配置(可选)
  • 参考链接:

Was this helpful?

  1. tools

YouCompleteMe

概念

YouCompleteMe 插件是一种基于语义分析的补齐:通过分析源文件,经过语法分析以后进行智能补全。

简称 YCM,是一款 Vim 下非常流行的自动代码补齐神器。

安装依赖软件和库

编译 YouCompleteMe 插件时需要依赖 cmake 构建 Makefile,且依赖 Python 源码头文件,Ubuntu 系统可以使用以下命令安装相关依赖。

$ sudo apt-get install build-essential cmake python-dev python3-dev

clang 是一个面向 C 族语言(C-family languages)的轻量级编译器,YouCompleteMe 插件依赖 clang 实现对 C 族语言的语义补全,

$ sudo apt-get install clang

下载 YouCompleteMe 源码

使用 Vundle 或 vim-plug 等 Vim 插件管理器从 github 获取 YouCompleteMe 最新的源码,官方推荐使用 Vundle

  • 基于Vundle安装 YouCompleteMe 源码

    在~/.vimrc中加入以下

    Plugin 'Valloric/YouCompleteMe'

    然后输入 :PluginInstall 进行

编译 YouCompleteMe

经历过上述3个步骤后,YouCompleteMe 插件还没法使用,此时打开 Vim 时会看到如下的报错:

The ycmd server SHUT DOWN (restart with ‘:YcmRestartServer’). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation.

这是因为,YouCompleteMe 需要手工编译出库文件 ycm_core.so (以及依赖的libclang.so) 才可使用。

使用 Vundle 下载的 YouCompleteMe 源码保存在目录 ~/.vim/bundle/YouCompleteMe,在该目录下执行 .

$ cd .vim/bundle/YouCompleteMe/
$ ./install.py --clang-completer

即可编译具有C族语言的语义补全功能的 YouCompleteMe 插件。

至此,YouCompleteMe 插件已经安装完成

配置 YCM

ycm安装成功后,还不能代码补全提示,需要配置 .ycm_extra_conf.py

参考YCM自带的 YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py

  • 设置全局配置文件,根据实际情况进行修改

    ```bash

    $ cp YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/

    或

    $ cp note/vim/.ycm_extra_conf.py ~/

$ vim /etc/vim/vimrc.local let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'

note/vim 目录有已经修改好的全局配置文件.ycm_extra_conf.py,可直接用于**C项目**

* 设置项目配置文件,根据实际情况进行修改
```bash
$ cp ~/.ycm_extra_conf.py <project root>

YCM配置文件的查找顺序是当前目录>上层目录>...>根目录>全局配置文件 搜索头文件的顺序是:-I 指定目录、-isystem 指定目录、标准系统目录

此时正常进行语义补全!!!

vim配置(可选)

""""""""""""""""YouCompleteMe""""""""""""""""""""
" 指定全局配置文件
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
" 自动加载 .ycm_extra_conf.py 配置文件
let g:ycm_confirm_extra_conf = 0
" 输入两个字母以上,自动进行语义补全
let g:ycm_semantic_triggers =  {
            \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
            \ 'cs,lua,javascript': ['re!\w{2}'],
            \ }
" 修改语义补全时的背景颜色为灰色
highlight PMenu ctermfg=0 ctermbg=242 guifg=black guibg=darkgrey
highlight PMenuSel ctermfg=242 ctermbg=8 guifg=darkgrey guibg=black

" 函数申明
nmap <C-d>c :YcmCompleter GoToDeclaration<CR>
" 函数定义
nmap <C-d>f :YcmCompleter GoToDefinition<CR>
" 显示语法错误详情
nmap <F4> :YcmDiags<CR>
" YCM提供的跳跃功能采用了vim的jumplist,
" 往前跳和往后跳的快捷键为Ctrl+O以及Ctrl+I

参考链接:

PrevioustranslatingNextcscope

Last updated 4 years ago

Was this helpful?

YouCompleteMe 中容易忽略的配置
为YCM配置ycm_extra_conf.py脚本