vim-clang


Ⅰ. 插件描述

Clang completion plugin for vim

Ⅱ. 基本信息

创建日期:  2013-02-01
使用用户:  178
Github星:  310
插件作者:  Jianjun Mao

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'justmao945/vim-clang'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'justmao945/vim-clang'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'justmao945/vim-clang'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/justmao945/vim-clang

Ⅳ. 文档说明

vim-clang

Gitter

Use of clang to parse and complete C/C++ source files.

C source

Installation

  • Require executable clang installed.
  • Putting the content of plugin/ into ~/.vim/plugin works.
  • Using a plugin manager, like pathogen.vim, is recommended.
    Installation via pathogen is done by

cd ~/.vim/bundle; git clone https://github.com/justmao945/vim-clang.git.

Why

I was a user of clang_complete and it's really a good job, but someday I found that
I must write another plugin to overcome some drawbacks of it.

vim-clang VS Rip-Rip/clang_complete

  1. User options can be set for different file types in vim-clang.

    let g:clang_c_options = '-std=gnu11'
    let g:clang_cpp_options = '-std=c++11 -stdlib=libc++'

  2. vim-clang is faster than clang_complete (not using libclang).
    vim-clang does not support libclang now, and I don't think it's a good idea to use cindex.py(python binding for clang) directly.

If you use clang_complete with libclang and open many C/C++ source files, you'll find that VIM eats up hundreds of MB RAM...

* vim-clang caches output of clang and reuses if the completion point is not changed and without errors.
* vim-clang only runs clang once to get completions and diagnostics.
  1. vim-clang is more friendly than clang_complete.

    • vim-clang uses the preview window to show prototypes for C/C++ sources.
      Generally, C++ source has many overload functions and most of completions are very complex,

    which is not good to put this into OmniComplete popup menu.

    • vim-clang uses a split window to show the caret diagnostics from clang.
      clang_complete uses quickfix window to show diagnostics without caret, but that's not the best choice...

    Because the caret diagnostics of clang including many useful infomation.

  2. vim-clang supports relative include path in .clang configuration file.

    proj/
    |-- .clang
    |-- include/
        |-- main.h
    |-- src/
        |-- main.c
    |-- test/
        |-- main_test.c
    
    $ cat .clang
    -I.
    
  3. Better PCH support. vim-clang will find stdafx.h.pch automatically.

vim-clang VS Valloric/YouCompleteMe

YouCompleteMe is more powerful than vim-clang, that has a well designed client-server
architecture to deal the memory problem in clang_complete.

Features

Asynchronized mode [new]

  • Now vim-clang supports to call clang executable asynchronously that it won't block
  1. during the completion. This is very useful if your project is large and the machine

is not very powerful to parse them in tens of milliseconds. In synchronized mode you'll
find that's too 'slow' to wait the completion...

  • This mode is implemented by starting another vim process to notify the finish of the
    completion, so +clientserver option is required to compile the vim(generally added).
  • GVIM is required to use this mode, seems given --servername ??? to vim is not working.
  • Job control is used to run clang when in neovim, which is really very nice! Thank you
    syswow.

Compile commands [new]

  • Use cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 to generate compile_commands.json
  • To use the compile commands database in vim-clang, set the g:clang_compilation_database
  1. in your vimrc to your cmake build path.
    let g:clang_compilation_database = './build'

Neomake integration [new]

  • vim-clang now adds the compilation arguments parsed from .clang and .clang.ow
    to Neomake configuration variables. This means that the include search paths

(-I) that are in the .clang files will be passed down to the clang and gcc
makers from Neomake without overriding your configuration.

  • vim-clang will also set the directory from where the maker will run, which is
    the directory where the first .clang or .clang.ow is.

The variables that are affected are:

  • g:neomake_cpp_clang_maker
  • g:neomake_cpp_gcc_maker
  • g:neomake_c_clang_maker
  • g:neomake_c_gcc_maker

Options and Commands

:h clang.txt

OS requirement

Tested on

  • Ubuntu 14.04
  • Mac OS X 10.10
  • Windows 7

添加新评论