class & function names highlighting in Vim

前端 未结 11 686
名媛妹妹
名媛妹妹 2020-11-29 15:23

I just recently set up my Vim environment from Textmate, after becoming addicted to its modal input.

However, syntax highlighting seems to be not so beautiful in Vim

相关标签:
11条回答
  • 2020-11-29 15:56

    Try using this plugin http://www.vim.org/scripts/script.php?script_id=2646 Its does all ctags highlighting very efficiently for you

    0 讨论(0)
  • 2020-11-29 16:01

    The Clighter plugin can also be considered, which is a

    plugin for c-family semantic source code highlighting, based on Clang
    

    However, requires fairly recent versions and software: vim 7.4.330 +python2 and libclang.

    0 讨论(0)
  • 2020-11-29 16:01

    To match C functions definitions only, this works for me:

    syn match    cCustomFuncDef display /\(\w\+\(\s\|*\)\+\)\@<=\w\+\s*(\@=/ 
    hi def cCustomFuncDef ctermfg=lightblue
    
    0 讨论(0)
  • 2020-11-29 16:03

    EDIT: color_coded may be too heavy for you. try octol/vim-cpp-enhanced-highlight. It supports C++11/14 and integrates what @Eduardo answers.

    Semantic based highlighter:
    I would recommend jeaye/color_coded, A vim plugin for libclang-based highlighting
    So sorry that i'm new to stackoverflow which means I've not enough reputation to post images. Go see its effects if you wanna give it a shot. :)

    Pros:

    • Easy installation
    • Semantic highlighting
    • Clighter mentioned as above, need vim compiled with python2.7. However, color_coded is written in C++ and provides lua binding -> C++.

    Cons:

    • It delays unless you make some vim events to acitve it.
    • Customization is bit harder; you need to edit syntax/color_coded.vim yourself. But customization has been placed on its roadmap.

    Although it's still under development, it's increasingly gaining attention.

    before after

    0 讨论(0)
  • 2020-11-29 16:03

    Use a plug-in for vim like Taglist or set up ctags or cscope integration with vim (here's a tutorial for the vim/cscope.)

    0 讨论(0)
  • 2020-11-29 16:08

    The one solution is to use built ctags database. So create one with the ctags utility. Then set the 'tags' variable and put the following to the

    ~/.vim/after/syntax/c.vim
    
    function! s:highlight()
        let list = taglist('.*')
    
        for item in list
            let kind = item.kind
    
            if kind == 'f' || kind == 'c'
                let name = item.name
                exec 'syntax keyword Identifier '.name
            endif
        endfor
    endfunction
    
    call s:highlight()
    

    I must warn you that this can work very slow on the very big ctags database.

    Also there is one solution on the vim.org but I didn't try this one. Let me know if it works for you.

    0 讨论(0)
提交回复
热议问题