1079 lines
39 KiB
Plaintext
1079 lines
39 KiB
Plaintext
|
*omnicppcomplete.txt* Plugin for C/C++ omnicompletion
|
||
|
*omnicppcomplete*
|
||
|
|
||
|
Author: Vissale NEANG (fromtonrouge AT gmail DOT com)
|
||
|
Last Change: 26 sept. 2007
|
||
|
|
||
|
OmniCppComplete version 0.41
|
||
|
|
||
|
For Vim version 7.0 and above
|
||
|
|
||
|
==============================================================================
|
||
|
|
||
|
1. Overview |omnicpp-overview|
|
||
|
2. Downloads |omnicpp-download|
|
||
|
3. Installation |omnicpp-installation|
|
||
|
4. Options |omnicpp-options|
|
||
|
5. Features |omnicpp-features|
|
||
|
6. Limitations |omnicpp-limitations|
|
||
|
7. FAQ & TIPS |omnicpp-faq|
|
||
|
8. History |omnicpp-history|
|
||
|
9. Thanks |omnicpp-thanks|
|
||
|
|
||
|
==============================================================================
|
||
|
1. Overview~
|
||
|
*omnicpp-overview*
|
||
|
The purpose of this script is to provide an 'omnifunc' function for C and C++
|
||
|
language. In a C++ file, while in insert mode, you can use CTRL-X CTRL-O to:
|
||
|
|
||
|
* Complete namespaces, classes, structs and unions
|
||
|
* Complete attribute members and return type of functions
|
||
|
* Complete the "this" pointer
|
||
|
* Complete an object after a cast (C and C++ cast)
|
||
|
* Complete typedefs and anonymous types
|
||
|
|
||
|
You can set a "may complete" behaviour to start a completion automatically
|
||
|
after a '.', '->' or '::'. Please see |omnicpp-may-complete| for more details.
|
||
|
|
||
|
The script needs an |Exuberant_ctags| database to work properly.
|
||
|
|
||
|
==============================================================================
|
||
|
2. Downloads~
|
||
|
*omnicpp-download*
|
||
|
You can download the latest release of the script from this url :
|
||
|
|
||
|
http://www.vim.org/scripts/script.php?script_id=1520
|
||
|
|
||
|
You can download |Exuberant_ctags| from :
|
||
|
|
||
|
http://ctags.sourceforge.net
|
||
|
|
||
|
==============================================================================
|
||
|
3. Installation~
|
||
|
*omnicpp-installation*
|
||
|
3.1. Script installation~
|
||
|
|
||
|
Unzip the downloaded file in your personal |vimfiles| directory (~/.vim under
|
||
|
unix or %HOMEPATH%\vimfiles under windows). The 'omnifunc' will be
|
||
|
automatically set for C and C++ files.
|
||
|
|
||
|
You also have to enable plugins by adding these two lines in your|.vimrc|file: >
|
||
|
|
||
|
set nocp
|
||
|
filetype plugin on
|
||
|
<
|
||
|
Please see |cp| and |filetype-plugin-on| sections for more details.
|
||
|
|
||
|
3.1.1. Files~
|
||
|
|
||
|
After installation you should find these files :
|
||
|
|
||
|
after\ftplugin\cpp.vim
|
||
|
after\ftplugin\c.vim
|
||
|
|
||
|
autoload\omni\common\debug.vim
|
||
|
\utils.vim
|
||
|
|
||
|
autoload\omni\cpp\complete.vim
|
||
|
\includes.vim
|
||
|
\items.vim
|
||
|
\maycomplete.vim
|
||
|
\namespaces.vim
|
||
|
\settings.vim
|
||
|
\tokenizer.vim
|
||
|
\utils.vim
|
||
|
|
||
|
doc\omnicppcomplete.txt
|
||
|
|
||
|
3.2. Building the Exuberant Ctags database~
|
||
|
|
||
|
To extract C/C++ symbols information, the script needs an |Exuberant_ctags|
|
||
|
database.
|
||
|
|
||
|
You have to build your database with at least the following options:
|
||
|
--c++-kinds=+p : Adds prototypes in the database for C/C++ files.
|
||
|
--fields=+iaS : Adds inheritance (i), access (a) and function
|
||
|
signatures (S) information.
|
||
|
--extra=+q : Adds context to the tag name. Note: Without this
|
||
|
option, the script cannot get class members.
|
||
|
|
||
|
Thus to build recursively a ctags database from the current directory, the
|
||
|
command looks like this:
|
||
|
>
|
||
|
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
|
||
|
<
|
||
|
You can add a map in your |.vimrc| file, eg: >
|
||
|
|
||
|
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
|
||
|
<
|
||
|
Or you can add these options in your ctags config file (~/.ctags under unix or
|
||
|
%HOMEPATH%\ctags.cnf under windows) and execute the command : >
|
||
|
|
||
|
:!ctags -R .
|
||
|
<
|
||
|
If your project contains files of other languages you may add the following
|
||
|
options:
|
||
|
--languages=c++ : Builds only the tags for C++ files.
|
||
|
|
||
|
If your project contains macros you may also use the -I option.
|
||
|
|
||
|
Please read the ctags help or ctags man page for more details.
|
||
|
|
||
|
3.3. Setting the 'tags' option~
|
||
|
|
||
|
The default value of the option 'tags' is "./tags,tags" ("./tags,./TAGS,tags,TAGS"
|
||
|
when |+emacs_tags| is enabled), if you build your tag database with the cmd above,
|
||
|
you normally don't have to change this setting (The cmd used above generates a
|
||
|
file with the name "tags"). In this case your current working directory must be
|
||
|
the directory where the tags file reside.
|
||
|
|
||
|
Note: When |+emacs_tags| is enabled, the script may display members twice, it's
|
||
|
recommended to set tags to "./tags,tags' or "./TAGS,TAGS".
|
||
|
|
||
|
If your tags file is not named "tags" you have to add it in the 'tags'
|
||
|
option eg: >
|
||
|
|
||
|
set tags+=/usr/tagsdir/mytagfile
|
||
|
<
|
||
|
You can ensure that the 'tags' option is set properly by executing the following
|
||
|
command: >
|
||
|
|
||
|
:tselect MyClass
|
||
|
<
|
||
|
Where MyClass is a class of your project. This command should display all
|
||
|
possible tags for the type MyClass.
|
||
|
|
||
|
3.4. Simple test~
|
||
|
|
||
|
Now you can do a simple test. Edit a C++ file and write the simplest case : >
|
||
|
|
||
|
MyClass myObject;
|
||
|
myObject.<C-X><C-O>
|
||
|
<
|
||
|
You should see class members of MyClass.
|
||
|
|
||
|
==============================================================================
|
||
|
4. Options~
|
||
|
*omnicpp-options*
|
||
|
|
||
|
You can change completion behaviour by setting script options in your |.vimrc|
|
||
|
configuration file.
|
||
|
|
||
|
4.1. Global scope search toggle~
|
||
|
*OmniCpp_GlobalScopeSearch*
|
||
|
|
||
|
You can enable/disable the global scope search by setting the
|
||
|
OmniCpp_GlobalScopeSearch option.
|
||
|
|
||
|
Possible values are :
|
||
|
0 = disabled
|
||
|
1 = enabled
|
||
|
[default=1] >
|
||
|
|
||
|
let OmniCpp_GlobalScopeSearch = 1
|
||
|
<
|
||
|
4.2. Namespace search method~
|
||
|
*OmniCpp_NamespaceSearch*
|
||
|
|
||
|
You can change the 'using namespace' search behaviour by setting the
|
||
|
OmniCpp_NamespaceSearch option.
|
||
|
|
||
|
Possible values are :
|
||
|
0 = namespaces disabled
|
||
|
1 = search namespaces in the current buffer
|
||
|
2 = search namespaces in the current buffer and in included files
|
||
|
[default=1] >
|
||
|
|
||
|
let OmniCpp_NamespaceSearch = 1
|
||
|
<
|
||
|
When OmniCpp_NamespaceSearch is 2, "using namespace" declarations are parsed
|
||
|
in the current buffer and also in included files. To find included files, the
|
||
|
script use the vim env 'path', so you have to set it properly.
|
||
|
|
||
|
Note: included files are searched with lvimgrep, thus the location list of the
|
||
|
current window is changed.
|
||
|
|
||
|
Note: When the 'filetype' is "c", namespace search is always disabled even if
|
||
|
OmniCpp_NamespaceSearch != 0
|
||
|
|
||
|
4.3. Class scope completion mode~
|
||
|
*OmniCpp_DisplayMode*
|
||
|
|
||
|
When you are completing a class scope (eg: MyClass::<C-X><C-O>), depending on
|
||
|
the current scope, you may see sometimes static, public, protected or private
|
||
|
members and sometimes you may see all members. By default the choice is done
|
||
|
automatically by the script but you can override it with the
|
||
|
OmniCpp_DisplayMode option.
|
||
|
|
||
|
Note: This option can be use when you have friend classes in your project (the
|
||
|
script does not support friend classes).
|
||
|
|
||
|
Possible values are :
|
||
|
0 = auto
|
||
|
1 = always show all members
|
||
|
[default=0] >
|
||
|
|
||
|
let OmniCpp_DisplayMode = 0
|
||
|
<
|
||
|
4.4. Show scope in abbreviation~
|
||
|
*OmniCpp_ShowScopeInAbbr*
|
||
|
|
||
|
By default, in the |omnicpp-popup| menu, you will see the scope of a match in
|
||
|
the last column. You can remove this column and add the scope at the beginning
|
||
|
of match abbreviation.
|
||
|
eg:
|
||
|
|
||
|
OmniCpp_ShowScopeInAbbr = 0
|
||
|
+-------------------------------------+
|
||
|
|method1( f + MyNamespace::MyClass|
|
||
|
|_member1 m + MyNamespace::MyClass|
|
||
|
|_member2 m # MyNamespace::MyClass|
|
||
|
|_member3 m - MyNamespace::MyClass|
|
||
|
+-------------------------------------+
|
||
|
|
||
|
OmniCpp_ShowScopeInAbbr = 1
|
||
|
+-------------------------------------+
|
||
|
|MyNamespace::MyClass::method1( f + |
|
||
|
|MyNamespace::MyClass::_member1 m + |
|
||
|
|MyNamespace::MyClass::_member2 m # |
|
||
|
|MyNamespace::MyClass::_member3 m - |
|
||
|
+-------------------------------------+
|
||
|
|
||
|
Possible values are :
|
||
|
0 = don't show scope in abbreviation
|
||
|
1 = show scope in abbreviation and remove the last column
|
||
|
[default=0] >
|
||
|
|
||
|
let OmniCpp_ShowScopeInAbbr = 0
|
||
|
<
|
||
|
4.5. Show prototype in abbreviation~
|
||
|
*OmniCpp_ShowPrototypeInAbbr*
|
||
|
|
||
|
This option allows to display the prototype of a function in the abbreviation
|
||
|
part of the popup menu.
|
||
|
|
||
|
Possible values are:
|
||
|
0 = don't display prototype in abbreviation
|
||
|
1 = display prototype in abbreviation
|
||
|
[default=0] >
|
||
|
|
||
|
let OmniCpp_ShowPrototypeInAbbr = 0
|
||
|
<
|
||
|
4.6. Show access~
|
||
|
*OmniCpp_ShowAccess*
|
||
|
|
||
|
This option allows to show/hide the access information ('+', '#', '-') in the
|
||
|
popup menu.
|
||
|
|
||
|
Possible values are:
|
||
|
0 = hide access
|
||
|
1 = show access
|
||
|
[default=1] >
|
||
|
|
||
|
let OmniCpp_ShowAccess = 1
|
||
|
|
||
|
4.7. Default using namespace list~
|
||
|
*OmniCpp_DefaultNamespaces*
|
||
|
|
||
|
When |OmniCpp_NamespaceSearch| is not 0, the script will parse using namespace
|
||
|
declarations in the current buffer and maybe in included files.
|
||
|
You can specify manually a default namespace list if you want with the
|
||
|
OmniCpp_DefaultNamespaces option. Each item in the list is a namespace name.
|
||
|
eg: If you have
|
||
|
|
||
|
let OmniCpp_DefaultNamespaces = ["std", "MyNamespace"]
|
||
|
|
||
|
It will be the same as inserting this declarations at the top of the
|
||
|
current buffer :
|
||
|
|
||
|
using namespace std;
|
||
|
using namespace MyNamespace;
|
||
|
|
||
|
This option can be use if you don't want to parse using namespace declarations
|
||
|
in included files and want to add namespaces that are always used in your
|
||
|
project.
|
||
|
|
||
|
Possible values are :
|
||
|
List of String
|
||
|
[default=[]] >
|
||
|
|
||
|
let OmniCpp_DefaultNamespaces = []
|
||
|
<
|
||
|
4.8. May complete behaviour~
|
||
|
*omnicpp-may-complete*
|
||
|
|
||
|
This feature allows you to run automatically a completion after a '.', '->'
|
||
|
or '::'. By default, the "may complete" feature is set automatically for '.'
|
||
|
and '->'. The reason to not set this feature for the scope operator '::' is
|
||
|
sometimes you don't want to complete a namespace that contains many members.
|
||
|
|
||
|
To enable/disable the "may complete" behaviour for dot, arrow and scope
|
||
|
operator, you can change the option OmniCpp_MayCompleteDot,
|
||
|
OmniCpp_MayCompleteArrow and OmniCpp_MayCompleteScope respectively.
|
||
|
|
||
|
*OmniCpp_MayCompleteDot*
|
||
|
Possible values are :
|
||
|
0 = May complete disabled for dot
|
||
|
1 = May complete enabled for dot
|
||
|
[default=1] >
|
||
|
|
||
|
let OmniCpp_MayCompleteDot = 1
|
||
|
<
|
||
|
*OmniCpp_MayCompleteArrow*
|
||
|
Possible values are :
|
||
|
0 = May complete disabled for arrow
|
||
|
1 = May complete enabled for arrow
|
||
|
[default=1] >
|
||
|
|
||
|
let OmniCpp_MayCompleteArrow = 1
|
||
|
<
|
||
|
*OmniCpp_MayCompleteScope*
|
||
|
Possible values are :
|
||
|
0 = May complete disabled for scope
|
||
|
1 = May complete enabled for scope
|
||
|
[default=0] >
|
||
|
|
||
|
let OmniCpp_MayCompleteScope = 0
|
||
|
<
|
||
|
|
||
|
Note: You can obviously continue to use <C-X><C-O>
|
||
|
|
||
|
4.9. Select/Don't select first popup item~
|
||
|
*OmniCpp_SelectFirstItem*
|
||
|
|
||
|
Note: This option is only used when 'completeopt' does not contain "longest".
|
||
|
|
||
|
When 'completeopt' does not contain "longest", Vim automatically select the
|
||
|
first entry of the popup menu. You can change this behaviour with the
|
||
|
OmniCpp_SelectFirstItem option.
|
||
|
|
||
|
Possible values are:
|
||
|
0 = don't select first popup item
|
||
|
1 = select first popup item (inserting it to the text)
|
||
|
2 = select first popup item (without inserting it to the text)
|
||
|
[default=0] >
|
||
|
|
||
|
let OmniCpp_SelectFirstItem = 0
|
||
|
|
||
|
4.10 Use local search function for variable definitions~
|
||
|
*OmniCpp_LocalSearchDecl*
|
||
|
|
||
|
The internal search function for variable definitions of vim requires that the
|
||
|
enclosing braces of the function are located in the first column. You can
|
||
|
change this behaviour with the OmniCpp_LocalSearchDecl option. The local
|
||
|
version works irrespective the position of braces.
|
||
|
|
||
|
Possible values are:
|
||
|
0 = use standard vim search function
|
||
|
1 = use local search function
|
||
|
[default=0] >
|
||
|
|
||
|
==============================================================================
|
||
|
5. Features~
|
||
|
*omnicpp-features*
|
||
|
5.1. Popup menu~
|
||
|
*omnicpp-popup*
|
||
|
Popup menu format:
|
||
|
+-------------------------------------+
|
||
|
|method1( f + MyNamespace::MyClass|
|
||
|
|_member1 m + MyNamespace::MyClass|
|
||
|
|_member2 m # MyNamespace::MyClass|
|
||
|
|_member3 m - MyNamespace::MyClass|
|
||
|
+-------------------------------------+
|
||
|
^ ^ ^ ^
|
||
|
(1) (2)(3) (4)
|
||
|
|
||
|
(1) name of the symbol, when a match ends with '(' it's a function.
|
||
|
|
||
|
(2) kind of the symbol, possible kinds are :
|
||
|
* c = classes
|
||
|
* d = macro definitions
|
||
|
* e = enumerators (values inside an enumeration)
|
||
|
* f = function definitions
|
||
|
* g = enumeration names
|
||
|
* m = class, struct, and union members
|
||
|
* n = namespaces
|
||
|
* p = function prototypes
|
||
|
* s = structure names
|
||
|
* t = typedefs
|
||
|
* u = union names
|
||
|
* v = variable definitions
|
||
|
|
||
|
(3) access, possible values are :
|
||
|
* + = public
|
||
|
* # = protected
|
||
|
* - = private
|
||
|
Note: enumerators have no access information
|
||
|
|
||
|
(4) scope where the symbol is defined.
|
||
|
Note: If the scope is empty it's a global symbol
|
||
|
Note: anonymous scope may end with __anon[number]
|
||
|
eg: If you have an anonymous enum in MyNamespace::MyClass : >
|
||
|
|
||
|
namespace MyNamespace
|
||
|
{
|
||
|
class MyClass
|
||
|
{
|
||
|
private:
|
||
|
|
||
|
enum
|
||
|
{
|
||
|
E_ENUM0,
|
||
|
E_ENUM1,
|
||
|
E_ENUM2
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
<
|
||
|
|
||
|
You should see :
|
||
|
|
||
|
+----------------------------------------------+
|
||
|
|E_ENUM0 e MyNamespace::MyClass::__anon1|
|
||
|
|E_ENUM1 e MyNamespace::MyClass::__anon1|
|
||
|
|E_ENUM2 e MyNamespace::MyClass::__anon1|
|
||
|
+----------------------------------------------+
|
||
|
^
|
||
|
__anon[number]
|
||
|
|
||
|
5.2. Global scope completion~
|
||
|
|
||
|
The global scope completion allows you to complete global symbols for the base
|
||
|
you are currently typing. The base can start with '::' or not.
|
||
|
Note: Global scope completion only works with a non empty base, if you run a
|
||
|
completion just after a '::' the completion will fail. The reason is that if
|
||
|
there is no base to complete the script will try to display all the tags in
|
||
|
the database. For small project it could be not a problem but for others you
|
||
|
may wait 5 minutes or more for a result.
|
||
|
|
||
|
eg1 : >
|
||
|
|
||
|
pthread_cr<C-X><C-O> => pthread_create
|
||
|
<
|
||
|
Where pthread_create is a global function.
|
||
|
eg2: >
|
||
|
::globa<C-X><C-O> => ::global_func(
|
||
|
+----------------+
|
||
|
|global_func( f|
|
||
|
|global_var1 v|
|
||
|
|global_var2 v|
|
||
|
+----------------+
|
||
|
<
|
||
|
Where global_var1, global_var2 and global_func are global symbols
|
||
|
eg3: >
|
||
|
::<C-X><C-O> => [NO MATCH]
|
||
|
<
|
||
|
No match because a global completion from an empty base is not allowed.
|
||
|
|
||
|
5.3. Namespace scope completion~
|
||
|
|
||
|
You can complete namespace members after a 'MyNamespace::'. Contrary to global
|
||
|
scope completion you can run a completion from an empty base.
|
||
|
Possible members are:
|
||
|
* Namespaces
|
||
|
* Classes
|
||
|
* Structs
|
||
|
* Unions
|
||
|
* Enums
|
||
|
* Functions
|
||
|
* Variables
|
||
|
* Typedefs
|
||
|
|
||
|
eg: >
|
||
|
MyNamespace::<C-X><C-O>
|
||
|
+--------------------------------+
|
||
|
|E_ENUM0 e MyNamespace|
|
||
|
|E_ENUM1 e MyNamespace|
|
||
|
|E_ENUM2 e MyNamespace|
|
||
|
|MyClass c MyNamespace|
|
||
|
|MyEnum g MyNamespace|
|
||
|
|MyStruct s MyNamespace|
|
||
|
|MyUnion u MyNamespace|
|
||
|
|SubNamespace n MyNamespace|
|
||
|
|doSomething( f MyNamespace|
|
||
|
|myVar v MyNamespace|
|
||
|
|something_t t MyNamespace|
|
||
|
+--------------------------------+
|
||
|
|
||
|
5.4. Class scope completion~
|
||
|
|
||
|
You can complete class members after a 'MyClass::'. Contrary to global scope
|
||
|
completion you can run a completion from an empty base.
|
||
|
By default, there is two behaviours for class scope completion.
|
||
|
|
||
|
a) Completion of a base class of the current class scope
|
||
|
|
||
|
When you are completing a base class of the current class scope, you
|
||
|
will see all members of this class in the popup menu.
|
||
|
eg: >
|
||
|
|
||
|
class A
|
||
|
{
|
||
|
public:
|
||
|
enum
|
||
|
{
|
||
|
E_ENUM0,
|
||
|
E_ENUM1,
|
||
|
E_ENUM2,
|
||
|
};
|
||
|
|
||
|
void func1();
|
||
|
static int _staticMember;
|
||
|
|
||
|
private:
|
||
|
int _member;
|
||
|
};
|
||
|
|
||
|
class B : public A
|
||
|
{
|
||
|
public:
|
||
|
void doSomething();
|
||
|
};
|
||
|
|
||
|
|
||
|
void MyClassB::doSomething()
|
||
|
{
|
||
|
MyClassA::<C-X><C-O>
|
||
|
+---------------------------+
|
||
|
|E_ENUM0 e MyClassA|
|
||
|
|E_ENUM1 e MyClassA|
|
||
|
|E_ENUM2 e MyClassA|
|
||
|
|func1( f + MyClassA|
|
||
|
|_member m - MyClassA|
|
||
|
|_staticMember m + MyClassA|
|
||
|
+---------------------------+
|
||
|
}
|
||
|
<
|
||
|
|
||
|
b) Completion of a non base class of the current class scope
|
||
|
|
||
|
When you are completing a class that is not a base class of the
|
||
|
current class you will see only enumerators and static members.
|
||
|
eg: >
|
||
|
|
||
|
class C
|
||
|
{
|
||
|
public:
|
||
|
void doSomething();
|
||
|
};
|
||
|
|
||
|
void MyClassC::doSomething()
|
||
|
{
|
||
|
MyClassA::<C-X><C-O>
|
||
|
+---------------------------+
|
||
|
|E_ENUM0 e MyClassA|
|
||
|
|E_ENUM1 e MyClassA|
|
||
|
|E_ENUM2 e MyClassA|
|
||
|
|_staticMember m + MyClassA|
|
||
|
+---------------------------+
|
||
|
}
|
||
|
<
|
||
|
You can override the default behaviour by setting the
|
||
|
|OmniCpp_DisplayMode| option.
|
||
|
|
||
|
5.5. Current scope completion~
|
||
|
|
||
|
When you start a completion from an empty instruction you are in "Current
|
||
|
scope completion" mode. You will see possible members of each context in
|
||
|
the context stack.
|
||
|
eg: >
|
||
|
void MyClass::doSomething()
|
||
|
{
|
||
|
using namespace MyNamespace;
|
||
|
using namespace SubNamespace;
|
||
|
|
||
|
// You will see members of each context in the context stack
|
||
|
// 1) MyClass members
|
||
|
// 2) MyNamespace::SubNamespace members
|
||
|
// 3) MyNamespace members
|
||
|
|
||
|
<C-X><C-O>
|
||
|
+------------------------------------------+
|
||
|
|_member1 m + MyClass |
|
||
|
|_member2 m # MyClass |
|
||
|
|func1( f MyNamespace::SubNamespace|
|
||
|
|var v MyNamespace::SubNamespace|
|
||
|
|func1( f MyNamespace |
|
||
|
|var v MyNamespace |
|
||
|
+------------------------------------------+
|
||
|
}
|
||
|
<
|
||
|
|
||
|
5.6. Class, Struct and Union members completion~
|
||
|
|
||
|
You can complete members of class, struct and union instances after a '->' or
|
||
|
'.'.
|
||
|
eg: >
|
||
|
MyClass myObject;
|
||
|
myObject.<C-X><C-O>
|
||
|
+-----------------------+
|
||
|
|_member1 m + MyClass |
|
||
|
|_member2 m # MyClass |
|
||
|
+-----------------------+
|
||
|
<
|
||
|
|
||
|
5.7. Attribute members and returned type completion~
|
||
|
|
||
|
You can complete a class member or a return type of a function.
|
||
|
eg: >
|
||
|
MyClass myObject;
|
||
|
|
||
|
// Completion of the member _member1
|
||
|
myObject._member1-><C-X><C-O>
|
||
|
+------------------------+
|
||
|
|get( m + AnotherClass1|
|
||
|
+------------------------+
|
||
|
|
||
|
// Completion of the return type of the function get()
|
||
|
myObject._member1->get()-><C-X><C-O>
|
||
|
+--------------------------+
|
||
|
|_member1 m + AnotherClass2|
|
||
|
|_member2 m # AnotherClass2|
|
||
|
|_member3 m - AnotherClass2|
|
||
|
+--------------------------+
|
||
|
|
||
|
5.8. Anonymous type completion~
|
||
|
|
||
|
Note: To use this feature you need at least|Exuberant_ctags| version 5.6
|
||
|
|
||
|
You can complete an anonymous type like this : >
|
||
|
struct
|
||
|
{
|
||
|
int a;
|
||
|
int b;
|
||
|
int c;
|
||
|
}globalVar;
|
||
|
|
||
|
void func()
|
||
|
{
|
||
|
globalVar.<C-X><C-O>
|
||
|
+---------------+
|
||
|
|a m + __anon1|
|
||
|
|b m + __anon1|
|
||
|
|c m + __anon1|
|
||
|
+---------------+
|
||
|
}
|
||
|
<
|
||
|
Where globalVar is a global variable of an anonymous type
|
||
|
|
||
|
5.9. Typedef completion~
|
||
|
|
||
|
You can complete a typedef. The typedef is resolved recursively, thus typedef
|
||
|
of typedef of... may not be a problem.
|
||
|
|
||
|
You can also complete a typedef of an anonymous type, eg : >
|
||
|
typedef struct
|
||
|
{
|
||
|
int a;
|
||
|
int b;
|
||
|
int c;
|
||
|
}something_t;
|
||
|
|
||
|
something_t globalVar;
|
||
|
|
||
|
void func()
|
||
|
{
|
||
|
globalVar.<C-X><C-O>
|
||
|
+---------------+
|
||
|
|a m + __anon1|
|
||
|
|b m + __anon1|
|
||
|
|c m + __anon1|
|
||
|
+---------------+
|
||
|
}
|
||
|
<
|
||
|
Where globalVar is a global variable of typedef of an anonymous type.
|
||
|
|
||
|
5.10. Completion of the "this" pointer~
|
||
|
|
||
|
You can complete the "this" pointer.
|
||
|
eg: >
|
||
|
this-><C-X><C-O>
|
||
|
+-----------------------+
|
||
|
|_member1 m + MyClass |
|
||
|
|_member2 m # MyClass |
|
||
|
+-----------------------+
|
||
|
|
||
|
(*this).<C-X><C-O>
|
||
|
+-----------------------+
|
||
|
|_member1 m + MyClass |
|
||
|
|_member2 m # MyClass |
|
||
|
+-----------------------+
|
||
|
<
|
||
|
|
||
|
5.11. Completion after a cast~
|
||
|
|
||
|
You can complete an object after a C or C++ cast.
|
||
|
eg: >
|
||
|
// C cast style
|
||
|
((AnotherStruct*)pStruct)-><C-X><C-O>
|
||
|
|
||
|
// C++ cast style
|
||
|
static_cast<AnotherStruct*>(pStruct)-><C-X><C-O>
|
||
|
<
|
||
|
|
||
|
5.12. Preview window~
|
||
|
|
||
|
If the 'completeopt' option contains the setting "preview" (this is the
|
||
|
default value), you will see a preview window during the completion.
|
||
|
This window shows useful information like function signature, filename where
|
||
|
the symbol is define etc...
|
||
|
|
||
|
The preview window contains tag information, the list below is non exhaustive.
|
||
|
|
||
|
* name : name of the tag
|
||
|
* cmd : regexp or line number that helps to find the tag
|
||
|
* signature : signature for prototypes and functions
|
||
|
* kind : kind of the tag (eg: namespace, class etc...)
|
||
|
* access : access information (eg: public, protected, private)
|
||
|
* inherits : list of base classes
|
||
|
* filename : filename where the tag is define
|
||
|
|
||
|
5.13. Code tokenization~
|
||
|
|
||
|
When you start a completion, the current instruction is tokenized ignoring
|
||
|
spaces, tabs, carriage returns and comments. Thus you can complete a symbol
|
||
|
even if the current instruction is on multiple lines, has comments between
|
||
|
words etc... :
|
||
|
eg: this case is unrealistic but it's just for illustration >
|
||
|
|
||
|
myObject [ 0 ]/* Why is there a comment here ?*/
|
||
|
->_member
|
||
|
-> <C-X><C-O>
|
||
|
<
|
||
|
|
||
|
==============================================================================
|
||
|
6. Limitations~
|
||
|
*omnicpp-limitations*
|
||
|
Some C++ features are not supported by the script, some implemented features
|
||
|
may not work properly in some conditions. They are multiple reasons like a
|
||
|
lack of information in the database, performance issues and so on...
|
||
|
|
||
|
6.1. Attribute members and returned type completion~
|
||
|
|
||
|
To work properly, the completion of attribute members and returned type of
|
||
|
functions depends on how you write your code in the class declaration.
|
||
|
Because the tags database does not contain information like return type or
|
||
|
type of a member, the script use the cmd information of the tag to determine
|
||
|
the type of an attribute member or the return type of a function.
|
||
|
|
||
|
Thus, because the cmd is a regular expression (or line number for #define) if
|
||
|
you write your code like this : >
|
||
|
|
||
|
class MyClass
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
MyOtherClass
|
||
|
_member;
|
||
|
};
|
||
|
<
|
||
|
The type of _member will not be recognized, because the cmd will be
|
||
|
/^ _member;$/ and does not contain the type MyOtherClass.
|
||
|
The correct case should be : >
|
||
|
|
||
|
class MyClass
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
MyOtherClass _member;
|
||
|
};
|
||
|
<
|
||
|
It's the same problem for return type of function : >
|
||
|
|
||
|
class MyClass
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
MyOtherClass
|
||
|
getOtherClass();
|
||
|
};
|
||
|
<
|
||
|
Here the cmd will be /^ getOtherClass();$/ and the script won't find the
|
||
|
return type.
|
||
|
The correct case should be : >
|
||
|
class MyClass
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
MyOtherClass getOtherClass();
|
||
|
};
|
||
|
<
|
||
|
|
||
|
6.2. Static members~
|
||
|
|
||
|
It's the same problem as above, tags database does not contain information
|
||
|
about static members. The only fast way to get this information is to use the
|
||
|
cmd.
|
||
|
|
||
|
6.3. Typedef~
|
||
|
|
||
|
It's the same problem as above, tags database does not contain information
|
||
|
about the type of a typedef. The script use the cmd information to resolve the
|
||
|
typedef.
|
||
|
|
||
|
6.4. Restricted inheritance access~
|
||
|
|
||
|
Tags database contains inheritance information but unfortunately inheritance
|
||
|
access are not available. We could use the cmd but we often find code
|
||
|
indentation like this : >
|
||
|
|
||
|
class A :
|
||
|
public B,
|
||
|
protected C,
|
||
|
private D
|
||
|
{
|
||
|
};
|
||
|
<
|
||
|
Here the cmd will be /^class A :$/, we can't extract inheritance access.
|
||
|
|
||
|
6.5. Using namespace parsing~
|
||
|
|
||
|
When you start a completion, using namespace declarations are parsed from the
|
||
|
cursor position to the first scope to detect local using namespace
|
||
|
declarations. After that, global using namespace declarations are parsed in the
|
||
|
file and included files.
|
||
|
|
||
|
There is a limitation for global using namespace detection, for performance
|
||
|
issues only using namespace that starts a line will be detected.
|
||
|
|
||
|
6.6. Friend classes~
|
||
|
|
||
|
Tags database does not contain information about friend classes. The script
|
||
|
does not support friend classes.
|
||
|
|
||
|
6.7. Templates~
|
||
|
|
||
|
At the moment, |Exuberant_ctags| does not provide additional information for
|
||
|
templates. That's why the script does not handle templates.
|
||
|
|
||
|
==============================================================================
|
||
|
7. FAQ & TIPS~
|
||
|
*omnicpp-faq*
|
||
|
|
||
|
* How to complete STL objects ?
|
||
|
If you have some troubles to generate a good ctags database for STL you
|
||
|
can try this solution :
|
||
|
|
||
|
1) Download SGI's STL from SGI's site
|
||
|
(http://www.sgi.com/tech/stl/download.html)
|
||
|
2) Replace all __STL_BEGIN_NAMESPACE by "namespace std {" and
|
||
|
__STL_END_NAMESPACE by "}" from header and source files. (with Vim,
|
||
|
or with tar and sed or another tool)
|
||
|
3) Run ctags and put the generated tags file in a directory eg:
|
||
|
~/MyTags/stl.tags
|
||
|
4) set tags+=~/MyTags/stl.tags
|
||
|
|
||
|
The main problem is that you can't tell to ctags that
|
||
|
__STL_BEGIN_NAMESPACE = "namespace std {" even with the option -I.
|
||
|
That's why you need the step 2).
|
||
|
|
||
|
Here is another solution if you have STL sources using _GLIBCXX_STD macro
|
||
|
(Tip by Nicola Bonelli) : >
|
||
|
|
||
|
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
|
||
|
<
|
||
|
* How to close automatically the preview window after a completion ?
|
||
|
(Tip by Kamil Renczewski)
|
||
|
|
||
|
You can add to your |vimrc| the following lines : >
|
||
|
|
||
|
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
|
||
|
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
|
||
|
<
|
||
|
==============================================================================
|
||
|
8. History~
|
||
|
*omnicpp-history*
|
||
|
Version O.41
|
||
|
- It's recommended to update ctags to version 5.7 or higher
|
||
|
- The plugin is now activated for C files
|
||
|
- New value for OmniCpp_SelectFirstItem when the option is equal to
|
||
|
2 the first item is selected without inserting it to
|
||
|
the text (patch from Marek Olszewski)
|
||
|
- Bug when completing union members fixed with ctags 5.7
|
||
|
(reported by Willem-Jan de Hoog)
|
||
|
- New option OmniCpp_LocalSearchDecl (patch from Roland Kuck)
|
||
|
- Bug when tags=something,,somethingelse (reported by Tobias Pflug)
|
||
|
- Bug with nested structure (reported by Mikhail Daen)
|
||
|
- Bug where the script fails to detect the type of a variable when
|
||
|
the ignorecase option is on (reported by Alexey Vakhov)
|
||
|
- Error message when trying to use completion on a not yet saved
|
||
|
Vim buffer (reported by Neil Bird)
|
||
|
- Error message when trying to use completion on an file opened from
|
||
|
a tselect command (reported by Henrique Andrade)
|
||
|
|
||
|
Version 0.4
|
||
|
- The script is renamed to OmniCppComplete according to the library
|
||
|
script directory structure.
|
||
|
- OmniCpp_ClassScopeCompletionMethod renamed to OmniCpp_DisplayMode
|
||
|
- Fixed a bug where the quickfix list is modified after a completion.
|
||
|
- OmniCpp_ShowPrototypeInAbbr option added. It allows to show the
|
||
|
function signature in the abbreviation.
|
||
|
- OmniCpp_ShowAccess option added. It allows to hide the access
|
||
|
information in the popup menu.
|
||
|
- The tags database format must be a ctags 5.6 database if you want to
|
||
|
complete anonymous types.
|
||
|
- Fixed current scope detection not working properly in destructors.
|
||
|
- Don't show protected and private members according to the current scope.
|
||
|
- Overloaded functions are now filtered properly.
|
||
|
- New cache system using less memory.
|
||
|
- The class scope of a method is now resolved properly with "using
|
||
|
namespace" declarations.
|
||
|
- OmniCpp_SelectFirstItem option added. It allows to not select the first
|
||
|
item in the popup menu when 'completeopt' does not contain "longest".
|
||
|
- Fixed the bug where a "random" item in the popup menu is selected
|
||
|
by default when 'completeopt' does not contain "longest" option.
|
||
|
- The script is now split in library scripts.
|
||
|
- Cache added for 'using namespace' search in included files
|
||
|
- Default value for OmniCpp_NamespaceSearch is now 1 (search only in the
|
||
|
current buffer).
|
||
|
- Namespace search automatically disabled for C files even if
|
||
|
OmniCpp_NamespaceSearch != 0.
|
||
|
- To avoid linear search in tags files, the ignorecase option is now
|
||
|
disabled when getting tags datas (the user setting is restored after).
|
||
|
- Fixed a bug where friend functions may crash the script and also crash vim.
|
||
|
|
||
|
Version 0.32
|
||
|
- Optimizations in search members methods.
|
||
|
- 'May complete' behaviour is now set to default for dot '.' and arrow
|
||
|
'->' (mappings are set in after/ftplugin/cpp.vim)
|
||
|
- Fixed the option CppOmni_ShowScopeInAbbr not detected after the first
|
||
|
completion.
|
||
|
- Exceptions catched from taglist() when a tag file is corrupted.
|
||
|
- Fixed a bug where enumerators in global scope didn't appear in the
|
||
|
popup menu.
|
||
|
|
||
|
Version 0.31
|
||
|
WARNING: For this release and future releases you have to build your tags
|
||
|
database with this cmd :
|
||
|
"ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
|
||
|
Please read installation instructions in the documentation for details
|
||
|
|
||
|
- May complete added, please see installation notes for details.
|
||
|
- Fixed a bug where the completion works while in a comment or in a string.
|
||
|
|
||
|
Version 0.3
|
||
|
WARNING: For this release and future releases you have to build your tags
|
||
|
database with this cmd :
|
||
|
"ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
|
||
|
Please read installation instructions in the documentation for details
|
||
|
|
||
|
- Documentation added.
|
||
|
- Fixed a bug where typedefs were not correctly resolved in namespaces
|
||
|
in some cases.
|
||
|
- Fixed a bug where the type can not be detected when we have a decl
|
||
|
like this: class A {}globalVar;
|
||
|
- Fixed a bug in type detection where searchdecl() (gd) find
|
||
|
incorrect declaration instruction.
|
||
|
- Global scope completion now only works with non-empty base.
|
||
|
- Using namespace list is now parsed in the current buffer and in
|
||
|
included files.
|
||
|
- Fixed a bug where the completion fails in some cases when the user
|
||
|
sets the ignorecase to on
|
||
|
- Preview window information added
|
||
|
- Some improvements in type detection, the type can be properly detected
|
||
|
with a declaration like this:
|
||
|
'Class1 *class1A = NULL, **class1B = NULL, class1C[9], class1D[1] = {};'
|
||
|
- Fixed a bug where parent scopes were not displayed in the popup menu
|
||
|
in the current scope completion mode.
|
||
|
- Fixed a bug where an error message was displayed when the last
|
||
|
instruction was not finished.
|
||
|
- Fixed a bug where the completion fails if a punctuator or operator was
|
||
|
immediately after the cursor.
|
||
|
- The script can now detect parent contexts at the cursor position
|
||
|
thanks to 'using namespace' declarations.
|
||
|
It can also detect ambiguous namespaces. They are not included in
|
||
|
the context list.
|
||
|
- Fixed a bug where the current scope is not properly detected when
|
||
|
a file starts with a comment
|
||
|
- Fixed a bug where the type is not detected when we have myObject[0]
|
||
|
- Removed the system() call in SearchMembers(), no more calls to the
|
||
|
ctags binary. The user have to build correctly his database with the cmd:
|
||
|
"ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
|
||
|
- File time cache removed, the user have to rebuild his data base after a
|
||
|
modification.
|
||
|
|
||
|
Version 0.22
|
||
|
- Completion of unnamed type (eg: You can complete g_Var defined like
|
||
|
this 'struct {int a; int b;}g_Var;'). It also works for a typedef of
|
||
|
an unnamed type (eg: 'typedef struct {int a; int b;}t_mytype; t_mytype
|
||
|
g_Var;').
|
||
|
- Tag file's time cache added, if a tag file has changed the global
|
||
|
scope result cache is cleared.
|
||
|
- Fixed a bug where the tokenization process enter in an infinite loop
|
||
|
when a file starts with '/*'.
|
||
|
|
||
|
Version 0.21
|
||
|
- Improvements on the global scope completion.
|
||
|
The user can now see the progression of the search and complete
|
||
|
matches are stored in a cache for optimization. The cache is cleared
|
||
|
when the tag env is modified.
|
||
|
- Within a class scope when the user complete an empty word, the popup
|
||
|
menu displays the members of the class then members of the global
|
||
|
scope.
|
||
|
- Fixed a bug where a current scope completion failed after a punctuator
|
||
|
or operator (eg: after a '=' or '!=').
|
||
|
|
||
|
Version 0.2
|
||
|
- Improvements in type detection (eg: when a variable is declared in a
|
||
|
parameter list, a catch clause, etc...)
|
||
|
- Code tokenization => ignoring spaces, tabs, carriage returns and comments
|
||
|
You can complete a code even if the instruction has bad
|
||
|
indentation, spaces or carriage returns between words
|
||
|
- Completion of class members added
|
||
|
- Detection of the current scope at the cursor position.
|
||
|
If you run a completion from en empty line, members of the current
|
||
|
scope are displayed. It works on the global namespace and the current
|
||
|
class scope (but there is not the combination of the 2 for the moment)
|
||
|
- Basic completion on the global namespace (very slow)
|
||
|
- Completion of returned type added
|
||
|
- this pointer completion added
|
||
|
- Completion after a cast added (C and C++ cast)
|
||
|
- Fixed a bug where the matches of the complete menu are not filtered
|
||
|
according to what the user typed
|
||
|
- Change the output of the popup menu. The type of the member
|
||
|
(function, member, enum etc...) is now display as a single letter.
|
||
|
The access information is display like this : '+' for a public member
|
||
|
'#' for a protected member and '-' for a private member.
|
||
|
The last information is the class, namespace or enum where the member is define.
|
||
|
|
||
|
Version 0.12:
|
||
|
- Complete check added to the search process, you can now cancel
|
||
|
the search during a complete search.
|
||
|
|
||
|
Version 0.1:
|
||
|
- First release
|
||
|
|
||
|
==============================================================================
|
||
|
9. Thanks~
|
||
|
*omnicpp-thanks*
|
||
|
* For advices, bug report, documentation, help, ideas :
|
||
|
Alexey Vakhov (bug report)
|
||
|
Arthur Axel "fREW" Schmidt (documentation)
|
||
|
Dennis Lubert (bug report)
|
||
|
Henrique Andrade (bug report)
|
||
|
Kamil Renczewski (tips)
|
||
|
Marek Olszewski (patch)
|
||
|
Markus Trenkwalder (bug report)
|
||
|
Martin Stubenschrott (bug report)
|
||
|
Mikhail Daen (bug report)
|
||
|
Neil Bird (bug report)
|
||
|
Nicola Bonelli (tips)
|
||
|
Robert Webb (bug report)
|
||
|
Roland Kuck (patch)
|
||
|
Tobias Pflug (bug report)
|
||
|
Willem-Jan de Hoog (bug report)
|
||
|
Yegappan Lakshmanan (advices)
|
||
|
|
||
|
|
||
|
* Darren Hiebert for Exuberant Ctags
|
||
|
|
||
|
* All Vim devs for Vim
|
||
|
|
||
|
* Bram Moolenaar for Vim
|
||
|
|
||
|
* You for using this script :)
|
||
|
|
||
|
==============================================================================
|
||
|
|
||
|
vim:tw=78:fo=tcq2:isk=!-~,^*,^\|,^\":ts=8:ft=help:norl:
|