sponsor Vim development Vim logo Vim Book Ad

clang_pro.vim : auto complete c/c++/java ,using gtags make a proj to find define and reference

 script karma  Rating 7/4, Downloaded by 375    Comments, bugs, improvements  Vim wiki

created by
yong xie
script type
This plugin use clang and  javacomplete to auto complete c/c++/java codes ,and use gnu global(work better than cscope for c++ and can work  for java and php) make a project to find define and callers.

All of the codes in the file are only less than 300 lines. So it is small but powerful.Everyone know vim script can read this plugin and change it for yourself. That is vim's power ,do it yourself. I use it work well for ubuntu 12.04 and old winxp machine, it may work well on mac X too.

Any one fix bug or use it on mac X give me a email at xieyong88881@163.com  ,i will happy.

For get the all utilities of the plugin,make install clang and gnu global,and put gtags.vim  in the source of global into your .vim/plugin.
Make  a file  name is clang_pro  at the root of your c/c++/java project.(all source file in it's dir or child dir)
As default key bindings,when you open a source file(.h .c .cpp .cc .cxx .java)
push ',' and 'd' keys on the word for define.
push ',' and 'r' for references.
push ',' and 'h' for h/c,cpp switch.
push ',' and 's' for save sessions.
push ',' and 'l' for load sessions.
push ',' and 'e' for error info.
push ',' and 'm' for will build the project using makeprg.
When add . :: -> complete menu will pop up for you. You can also use key ctrl-x-o make the complete menu pop up manully.

clang_pro file will work well for keys ,d ,r ,h ,s ,l functions with nothing in it,but for c/c++/java auto complete,it may need compile info lines like:
"for cpp
set makeprg=source\ env.sh;make
let g:clang_options = '-I ./include -I /opt/lib/include'
"or for java
"set makeprg=ant
"let g:java_classpath='.:/skyics/ics/out/host/common/obj/JAVA_LIBRARIES/layoutlib_intermediates/classes'
With right settings in clang_pro file for your project.  the ",m" key binding.and auto complete when meeting . -> :: will work well.

This plugin only use clang not libclang.so,it give method to use project file auto make a pch file for speed, most of time it quick enough ,if it is   slow for your project, you can  write line in your .vimrc or in clang_pro file at root of your project .
let g:clang_auto = 0  "only when you need ,ctrl-x-o to complete it.
other lines can add:
let g:clang_auto_map=0  "close default keys bindings
let g:clang_exe= 'clang'  "you can use other clang name
let g:clang_project = 'clang_pro'   "you can change the project file.
To other configure, make them in project file may better.like:
let g:clang_options = '-I "E:"Microsoft Visual Studio\VC98\Include" -I ./include '
let g:clang_use_pch="#include <vector>\n#include <list>"

When the script start ,it will find the clang_pro file and make it work,so can write any vim settings in it .
If you want a project which can quickly find define and callers .
GNU GLOBAL will make a GTAGS in the root of project, you can use the abilities of it.
You can use let g:clang_options to make clang work right, most of time ,include -I and macro define -D is needed.
And if the c/c++ header file is large for compile,you can use  g:clang_use_pch add pch file for clang, use \n to split these headers.
the quickfix windows will not pop at  auto complete.
It is better to make the function of getting err info alone,the quickfix windows will not pop at  auto complete.
install details
just put clang_pro.vim in your ~/.vim/plugin
install clang and GNU GLOBAL,(apt-get install clang and for new version in global source using configure/make/make install
install vim plugin: gtags.vim from gnu global source dir download new version from http://gnu.april.org/software/global/
and javacomplete from http://www.vim.org/scripts/script.php?script_id=1785  ;

make a file named clang_pro at the root of your c/c++/java project. the content can be like
when using a c/cpp pro using autotools for makefile,the sample content can be:

set makeprg=export\ PATH=$PATH:/opt/buildroot-gcc342/bin;cd\ ~/wifidog;make
let g:clang_options = '-I ./include -I ../include'
"notice must use "\" before when there are  ' ' in commands

when using a java pro using ant for make,the sample content can be:

set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
set makeprg=ant
let g:java_classpath='.:/skyics/ics/out/host/common/obj/JAVA_LIBRARIES/layoutlib_intermediates/classes'

When the script start ,it will find the clang_pro file and make it work,so can write any vim settings in it .
As default ,GNU GLOBAL will make a GTAGS in the root of project, you can
use the abilility of it which can quickly find define and callers. You can use let g:clang_options to make clang work , most of time ,include and macro define is needed.

If you do not want a project using gtags,write:  let g:clang_use_global = 0.

And if the head file is large,you can use  g:clang_use_pch add pch file for clang, use \n to split these headers.  for example:  let g:clang_use_pch="#include <vector>\n#include <list>"

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
clang_pro.vim 3.8 2014-08-28 7.0 yong xie add key binding ",e" for error info,now only work for cpp
clang_pro.vim 3.7 2014-08-19 7.0 yong xie fix c++ head/source file switch can't use .cc file bug.
clang_pro.vim 3.6 2014-08-15 7.0 yong xie remove '#' make clang complete more clear
clang_pro.vim 3.5 2014-07-09 7.0 yong xie only bug fix
clang_pro.vim 3.4 2014-06-13 7.0 yong xie add default key ,m for :make<CR>
clang_pro.vim 3.3 2014-06-06 7.0 yong xie add default keys
,s for saveSession.
,l for loadSession when in clang_pro subdir
clang_pro.vim 3.2 2014-06-03 7.0 yong xie add default key map
nmap ,d for find define
nmap ,r for find reference
nmap ,h for switch h/c,cpp
clang_pro.vim 3.1 2014-05-29 7.0 yong xie add cscope compatible,can use  command :cs find ...., add command :HCppSwitch   for goto h file and c/cpp file
clang_pro.vim 3.0 2014-05-27 7.0 yong xie add auto java complete
clang_pro.vim 2.1 2014-05-26 7.0 yong xie make start vim when using clang_pro build gtags pro quickly.
clang_pro.vim 2.0.1 2014-05-22 7.0 yong xie when has clang_pro file,make let g:clang_use_global = 1 as default,you can put line:
let g:clang_use_global = 0
in your clang_pro file to close gnu global auto create gtags file for your project.  
clang_pro.vim 2.0 2014-05-04 7.0 yong xie add function for session. When has clang_pro file, you can use :ClangSetSesion and :clangGetSession command save and load session at any c/c++ file in project.
clang_pro.vim 1.2 2014-04-25 7.0 yong xie fix bug for when  no clang_pro file complete work err.
clang_pro.vim 1.1 2014-04-23 7.0 yong xie some bug fix, make -I relative path can work and windows make gtags project err fixed.  
clang_pro.vim 1.0 2014-04-21 7.0 yong xie Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo