2013-12-12

OmniCppComplete Installation for Dummies

Note: In Stack Overflow question 12339415, it is suggested that clang is better. For its installation, refer to its another fan's blog.
Background: OmniCppComplete is a great Vim plugin that has the popup menu like many big IDEs. A Youtube video can show the power of OmniCppComplete.
Download: OmniCppComplete requires ctags.
  1. OmniCppComplete: GitHub Repository (To avoid mixing up of files from different plugins, use one plugin management plugin like Pathogen or Vundle.)
  2. Ctags: Official homepage on SourceForge (The .zip file for Win* 2**0 is fine.)
For more detailed information on the installation of ctags, please refer to my earlier blog post Links to Good Posts.
Problem: Reading the OmniCppComplete's documentation only, you won't be able to understand how to use this plugin, so follow some tutorials, and the most viewed one should be on Vim Tips Wiki. Followed its guidance, I got error in typing std:: in a new .cpp file. Omni completion told me something like "pattern not match". I spent nearly 2 hours to figure out what's wrong, and finally managed to fully understand the contents of this blog entry.
Now, I'm going to make a Win* version of Vim Tips Wiki's tutorial, using the ideas from Carl.
Solution:
  1. I suppose OmniCppComplete and ctags are installed properly.
    • OmniCppComplete does not mix up with other plugins.
      Note: For gVimPortable, do store files under the Data folder, but NOT the $VIMRUNTIME file. Otherwise the settings will be lost after upgrading gVimPortable.
    • The folder for different plugins are separated (except the plugin management plugin itself).
    • Typing :h omnicppcomplete in Vim normal mode gives up the help file for OmniCppComplete.
    • Typing :h omnicppcomplete gives you the corresponding help file.
    • The folder for ctags is in the PATH environment variable.
      Follow this page for setting the PATH variable.
      C:\ctags58 should be in the PATH variable.
  2. Download the modified libstdc++ headers from GitHub.
  3. Unzip the folder and place it under "somewhere meaningful to you"
    My suggestion: C:\Users\[your-user-name]\.vim
    Here you can substitute [your user name] with your real user name on Win*.
    Note: In the dialogue (in case you use GUI), DON'T input tags at the end. Otherwise, you'll get C:\Users\[your-user-name]\.vim\tags\tags
  4. If things go right, you should have C:\Users\[your-user-name]\.vim\tags
    Go to that directory by typing cd .vim\tags in Win*'s Command Prompt, which can be involked by typing cmd in the "Start" menu. (For XP, choose "Run" and type "cmd" in the popup dialogue. If you like choosing from the menu, follow the way on the official website.)
    At first, a commad prompt should be like this.
    The current directory is C:\Users\Owner.
    Change the current directory to C:\Users\Owner\.vim\tags.
    The contents should be shown by typing dir (There're so many files that I use the /w option to save space.)
  5. The contents are in the right place, so we may proceed.
    Get a list of ctags.
    To get a list of ctags, the correct command:
    >ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f cpp .
    The one you see on Vim Tips Wiki:
    >ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f cpp cpp_src
  6. Then you should have a huge list of ctags with the file name cpp. Not adding the additional tags for OpenGL, etc, is OK.
  7. Finally, adding the lines found in the Vim Tips Wiki into your vimrc will do.
    Note: If you don't add the additional tags in step 5, then the following lines should NOT be added.
    set tags+=~/.vim/tags/gl
    set tags+=~/.vim/tags/sdl
    set tags+=~/.vim/tags/qt4

Testing

A picture can illustrate the feature well. Typing std::, you'll get a popup list.

Incompatibility with clang_complete

Note that Omnicppcomplete is incompatible with another Vim plugin called clang_complete, due to its "unconditional popup of completion list". To understand this, the following pictures give a good interpretation.

In Omnicppcomplete, after typing std::, the completion list will pop up.
However, in clang_complete, since the information is from the clang compiler, you need to give the syntax in the right position for the compiler so as to let the completion list to show up.

Missing #include<iostream>
Still wrong position of the input
Right position
In Ubuntu, it's easy to install. Note that you need clang-dev as well. For Win*, maybe you need to download the source. (I hope there will be a compiled version of the compiler.)

Reference:
[1]: http://hi.baidu.com/dt_zhangwei/item/277572044909fc103a53eea5

No comments:

Post a Comment