How to configure YouCompleteMe to develop kernel drivers and devices?

I would like to configure vim to crack the kernel, so I installed YouCompleteMe to automatically terminate. However, no matter what I do, it looks like I cannot configure it correctly. It does not perform semantic completion properly; It offers only the semantics already used in the current file, not even in the headers or other translation units, and if that is not possible, then ycm is pretty useless. Does anyone know how to do this for a specific purpose? If you need to include mine .vimrcor .ycm_extra_conf.pyplease post in the comments. Also, if I need additional tools, please specify them so that I can customize them as well.

+4
source share
2 answers

This is how I set up the kernel programming environment with vim.

Used tools:

  • OmniCompletion : built-in vim function (without additional plugins) for automatic completion
  • ctags : creates the code index database, which is necessary for OmniCompletion (and some other vim plugins)
  • cscope : a tool for code navigation (for example, you can go directly to the definition of the function under cursor, etc.). Creates its own code index database (other than ctags).

1. Install tools

First install vim, ctags and cscope:

$ sudo aptitude install vim vim-gtk cscope exuberant-ctags

2. Create an index database

cscope ctags. script ( ):

#!/bin/bash

list_sources() {
    echo "---> Listing sources..."

    find .                                   \
        -path "./arch*" -prune -o            \
        -path "./tmp*" -prune -o             \
        -path "./Documentation*" -prune -o   \
        -path "./scripts*" -prune -o         \
        -type f -name "*.[chsS]" -print >cscope.files

    find arch/arm/include/                   \
        arch/arm/kernel/                     \
        arch/arm/common/                     \
        arch/arm/boot/                       \
        arch/arm/lib/                        \
        arch/arm/mm/                         \
        arch/arm/mach-omap2/                 \
        arch/arm/plat-omap/                  \
        -type f -name "*.[chsS]" -print >>cscope.files
}

create_cscope_db() {
    echo "---> Creating cscope DB..."
    cscope -k -b -q
}

create_ctags_db() {
    echo "---> Creating CTags DB..."
    ctags -L cscope.files
}

cleanup() {
    echo "---> Removing garbage..."
    rm -f cscope.files
}

list_sources
create_cscope_db
create_ctags_db
cleanup

script ARM ( OMAP). (, x86), find script.

script , :

  • (cscope.files), find.
  • cscope ( cscope.files ) (. -k man cscope), :

    $ cscope -b -q -k
    
  • ctags (tags), cscope.files (. man ctags):

    $ ctags -L cscope.files
    
  • cscope.files, .

3. vim cscope

cscope_maps.vim ~/.vim/plugin (. ).

vim , Ctrl+\, g, Ctrl+\, s .. . this. :help cscope-find vim.

4. vim OmniCompletion

OmniCompletion, ~/.vimrc. , OmniCompletion ( ~/.vimrc):

"-------------------------------------------------------------------------------
" OmniCppCompletion plugin
"-------------------------------------------------------------------------------

" Enable OmniCompletion
" http://vim.wikia.com/wiki/Omni_completion
filetype plugin on
set omnifunc=syntaxcomplete#Complete

" Configure menu behavior
" http://vim.wikia.com/wiki/VimTip1386
set completeopt=longest,menuone
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
  \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
  \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

" Use Ctrl+Space for omni-completion
" http://stackoverflow.com/questions/510503/ctrlspace-for-omni-and-keyword-completion-in-vim
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
  \ "\<lt>C-n>" :
  \ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
  \ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
  \ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>

" Popup menu hightLight Group
highlight Pmenu ctermbg=13 guibg=LightGray
highlight PmenuSel ctermbg=7 guibg=DarkBlue guifg=White
highlight PmenuSbar ctermbg=7 guibg=DarkGray
highlight PmenuThumb guibg=Black

" enable global scope search
let OmniCpp_GlobalScopeSearch = 1
" show function parameters
let OmniCpp_ShowPrototypeInAbbr = 1
" show access information in pop-up menu
let OmniCpp_ShowAccess = 1
" auto complete after '.'
let OmniCpp_MayCompleteDot = 1
" auto complete after '->'
let OmniCpp_MayCompleteArrow = 1
" auto complete after '::'
let OmniCpp_MayCompleteScope = 0
" don't select first item in pop-up menu
let OmniCpp_SelectFirstItem = 0

OmniCompletion ctags (tags). , Ctrl+Space ( vim ).

5.

:

+3

All Articles