1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
|
*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:
|