-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsupport.cnx
More file actions
2145 lines (1634 loc) · 92.7 KB
/
csupport.cnx
File metadata and controls
2145 lines (1634 loc) · 92.7 KB
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
*csupport.txt* C/C++ Support 2011-06-26
C/C++ Support *c-support* *csupport*
插件版本 5.14
针对 Vim version 7.0 及其以上版本
作者: Fritz Mehner <mehner@fh-swf.de>
译者: Tiger Lee <i.m.tiger.lee[AT]gmail.com>
Vim/gVim 的 C/C++-IDE。开发它是为了极为迅速地以一致的风格来编写代码。这是通过
插入整句,惯用法,代码片断,模板和注释来完成的。并可使用一键来完成语法检查,
编译,运行程序,运行代码检查工具或重新格式化代码。
1. 在 GUI 下使用 |csupport-usage-gvim|
1.1 'Comments' 菜单 |csupport-comm|
1.1.1 追加已对齐注释 |csupport-comm-aligned|
1.1.2 调整行尾注释 |csupport-comm-realign|
1.1.3 代码转注释 |csupport-code-to-comm|
1.1.4 注释转代码 |csupport-comm-to-code|
1.1.5 框注释,文件头,... |csupport-comm-frame|
1.1.6 文件区块注释... |csupport-comm-sections|
1.1.7 关键字注释,特殊注释 |csupport-comm-keyword|
1.1.8 标记(插件) |csupport-comm-tags|
1.1.9 日期和日期+时间 |csupport-comm-date|
1.1.10 C 注释转 C++ 注释,反之亦然 |csupport-comm-c-cpp|
1.2 'Statements' 菜单 |csupport-stat|
1.2.1 正常模式,插入模式 |csupport-stat-normal-mode|
1.2.2 可视模式 |csupport-stat-visual-mode|
1.3 'Preprocessor' 菜单 |csupport-prep|
1.3.1 正常模式,插入模式 |csupport-prep-normal-mode|
1.3.2 可视模式 |csupport-prep-visual-mode|
1.3.3 用 #if 0 .. #endif 封闭代码 |csupport-prep-if0|
1.3.4 外部命令 |csupport-prep-ex|
1.4 'Idioms' 菜单 |csupport-idioms|
1.4.1 'function' 项 |csupport-idioms-function|
1.4.2 for 循环控制 |csupport-idioms-for-loop|
1.4.3 'open input file' 项 |csupport-idioms-input|
1.4.4 'open output file' 项 |csupport-idioms-output|
1.5 'Snippets' 菜单 |csupport-snippets|
1.5.1 代码片断 |csupport-snippets|
1.5.2 选择原型 |csupport-proto|
1.5.3 代码模板 |csupport-templates-menu|
1.6 'C++' 菜单 |csupport-c++|
1.6.1 正常模式,插入模式 |csupport-c++-normal-mode|
1.6.2 可视模式 |csupport-c++-visual-mode|
1.6.3 方法实现 |csupport-c++-method-impl|
1.6.4 外部命令 |csupport-c++-ex|
1.7 'Run' 菜单 |csupport-run|
1.7.1 最小 make 功能 |csupport-run-buffer|
1.7.2 命令行参数 |csupport-run-cmdline-args|
1.7.3 运行 make |csupport-run-make|
1.7.4 运行可执行程序 |csupport-run-make-run|
1.7.5 运行 make clean |csupport-run-make-clean|
1.7.6 make 命令行参数 |csupport-run-make-args|
1.7.7 Splint |csupport-run-splint|
1.7.8 CodeCheck |csupport-run-codecheck|
1.7.9 缩进 |csupport-run-indent|
1.7.10 硬拷贝 |csupport-run-hardcopy|
1.7.11 重新构建模板 |csupport-run-templates|
1.7.12 Xterm 大小 |csupport-run-xterm|
1.7.13 输出重定向 |csupport-run-output|
1.8 帮助 |csupport-help|
2. 没有 GUI 时的用法 |csupport-usage-vim|
3. 快捷键 |csupport-hotkeys|
4. 定制和配置 |csupport-custom|
4.1 全局变量 |csupport-custom-glob-vars|
4.2 根目录 |csupport-custom-root|
4.3 系统级安装 |csupport-system-wide|
5. 模板和 tags |csupport-templates|
5.1 模板文件 |csupport-templates-files|
5.2 宏 |csupport-templates-macros|
5.2.1 用户定义格式的日期和时间 |csupport-templates-date|
5.3 模板 |csupport-templates-names|
5.3.1 模板名 |csupport-templates-names|
5.3.2 模板定义 |csupport-templates-definition|
5.3.3 模板展开 |csupport-templates-expansion|
5.3.4 宏 <+text+> 及其它 |csupport-templates-jump|
5.3.5 Ctrl-j 命令 |csupport-Ctrl-j|
5.4 模板集间切换 |csupport-templates-sets|
5.5 绑定风格到扩展名 |csupport-templates-bind|
6. C/C++ 字典 |csupport-dictionary|
7. 扩展 ctags |csupport-ctags|
7.1 Make 和 qmake |csupport-ctags-make|
7.2 模板 |csupport-ctags-templates|
8. 代码折叠 |csupport-folding|
9 额外映射 |csupport-ad-mappings|
10. Windows 特性 |csupport-windows|
11. 额外提示 |csupport-tips|
12. 问题排除 |csupport-troubleshooting|
13. 发布注解 / 变更日志 |csupport-release-notes|
怎样把这个帮助文件加入到 Vim 的帮助中 |add-local-help|
==============================================================================
1. 在 GUI 下使用 (gVim) *csupport-usage-gvim*
==============================================================================
如果看不见根菜单 'C/C++',则可从根菜单 'Tools' 的子项 "Load C Support" 启用它。
菜单项 "Load C Support" 同样也可用于卸载根目录 'C/C++'。
几乎所有的菜单项都会插入代码片断或注释。所有这些都包含在模板文件中,并且可以由
用户修改以达到他们的需求(参见|csupport-templates|)。
------------------------------------------------------------------------------
1.1 'Comments' 菜单 *csupport-comm*
------------------------------------------------------------------------------
1.1.1 在连续行中追加已对齐的注释 *csupport-comm-aligned*
在正常模式,菜单项 "end-of-line comment" 将会在当前行追加一条注释。
在可视模式,这个选项将会在所有已标记的行追加已对齐的注释。
标记前面 4 行。
print_double_array ( double array[],
int n,
int columns,
char* arrayname
)
并且选中 'end-of-line com',将会产生 '/* */'。
print_double_array ( double array[], /* */
int n, /* */
int columns, /* */
char* arrayname /* */
)
如果有一行或多行超过起始列,注释将会在最长那行之后的第二列开始。光标将会放置
在第一条注释里。
默认的起始列是 49 ( = (2,4 或 8 的倍数)+ 1)。这个值可以在文件 ~/.vimrc 中
设定一个全局变量来改变,如:
let g:C_LineEndCommColDefault = 45
起始列也可以由菜单项 'Comments->set end-of-line com. col' 设定。只需将光标放置
于任意列(列数显示在Vim的状态栏)并且选择这个菜单项。这个设定与缓冲区有关。
如果光标位于行尾,你将会被询问一个列数,因为这个位置极有可能不是想要的起始列。
你的选择会被确认。
------------------------------------------------------------------------------
1.1.2 调整行尾注释 *csupport-comm-realign*
在一些改动后,行尾注释可能不再整齐了:
print_double_array ( double array[], /* */
long int n, /* */
unsigned int columns, /* */
char* a_name /* */
) /* */
使用菜单项 'adjust end-of-line com.' 可以实现重新对齐。 在正常模式下,当前行的
注释(如果有的话)会尽可能的与行尾注释列(如下)对齐。在可视模式下,标记的块会
被对齐:
print_double_array ( double array[], /* */
long int n, /* */
unsigned int columns, /* */
char* a_name /* */
) /* */
只有前导空格的注释不会重新对齐,它们通常都是标题:
max = other.max; /* the maximum value */
len = other.len; /* the length */
/* ===== the next section ===== */
pos = (x+y+z)/3.0; /* the next position */
在对齐之后:
max = other.max; /* the maximum value */
len = other.len; /* the length */
/* ===== the next section ===== */
pos = (x+y+z)/3.0; /* the next position */
------------------------------------------------------------------------------
1.1.3 代码转注释 *csupport-code-to-comm*
标记块
xxxxxxxx
xxxxxxxx
xxxxxxxx
将会由菜单项 'code->comment /**/' 变成多行注释(全部或部分标记的行):
/* xxxxxxxx
* xxxxxxxx
* xxxxxxxx
*/
标记块将会由菜单项 'code->comment //' 变成多行注释:
//xxxxxxxx
//xxxxxxxx
//xxxxxxxx
这两个菜单项也作用于单行,但没必要先标记单行。
------------------------------------------------------------------------------
1.1.4 注释转代码 *csupport-comm-to-code*
如果标记了一行(或多行)完整的注释(如:所有的行都属于注释),菜单项
"comment->code" 将会取消注释,如果标记了以下行:
* printf ("\n");
*/
printf ("\n");
// printf ("\n");
//
/*
* printf ("\n");
*/
取消注释将会变成
* printf ("\n");
*/
printf ("\n");
printf ("\n");
printf ("\n");
前两行仅仅是 C 注释的一部分,所以保持不变。一条 C 注释的开始可以是 /*,/** 或者
/*!。
这个菜单项也作用于前导为 // 的单行,但没必要先标记单行。
------------------------------------------------------------------------------
1.1.5 框注释,文件头,... *csupport-comm-frame*
框注释、文件头注释、函数注释、方法注释和类描述注释都是从对应的文件中做为模板
读取的。(参见 |csupport-templates|)。
一共有两种类型的文件描述模板(菜单项 "file description (impl.)" 和
"file description (header)",同样参见 |csupport-templates|):
comment.file-description : 文件 *.c, *.cc, *.cp, *.cxx, *.cpp, *.CPP,
*.c++, *.C, *.i, *.ii
comment.file-description-header : 所有文件类型为 'c' 或 'cpp'
同样,适当的模板将会被包含进一个新文件。这由插件根据文件扩展名来决定。默认
显示上述模板。你可以在 '~/.vimrc' 中设置一个全局变量来改变这个扩展名列表。
au BufRead,BufNewFile *.XYZ set filetype=c
let g:C_SourceCodeExtensions = 'XYZ c cc cp cxx cpp CPP c++ C i ii'
新文件 'test.XYZ' 将会被认为是一个 C 的实现文件。
------------------------------------------------------------------------------
1.1.6 文件区块注释 *csupport-comm-sections*
文件区块注释可以用相似风格的注释来分隔典型的 C 和 H 文件区块,如:
/* ##### HEADER FILE INCLUDES ################################################### */
/* ##### MACROS - LOCAL TO THIS SOURCE FILE ################################### */
/* ##### TYPE DEFINITIONS - LOCAL TO THIS SOURCE FILE ######################### */
在 C/C++ 文件中,也可以使用快捷键 \ccs 来插入这些区块注释,或是在头文件中使用 \chs。
这些快捷键会在命令栏执行 'CFileSection' 或 'HFileSection':
:CFileSection
:HFileSection
现在,按下 <Tab> 键显示选项菜单,并从中挑一个吧。
------------------------------------------------------------------------------
1.1.7 关键字注释,特殊注释 *csupport-comm-keyword*
关键字注释是行尾注释:
/* :<关键字>:<date+time>:<author reference>: <arbitrary comment text> */
关键字包括:
BUG COMPILER TODO TRICKY WARNING WORKAROUND 用户自定义关键字
这些预备注释是用于标注快速恢复工作的位置。它们通常意味着不是为了最终文档。这些
注释可以很容易地通过关键字搜索到。
关键字注释也可以使用快捷键 \ckc。这个快捷键会在命令栏运行命令 "KeywordComment":
:KeywordComment
现在按下 <Tab> 调出选择菜单来挑一个。
特别注释偶尔用于在一段代码构成中注明特别的特性(如:在一个switch语句中失败的
情况, 一个空循环):
/* EMPTY */
/* NOT REACHED */
/* REMAINS TO BE IMPLEMENTED */
....
特殊注释也可以使用快捷键 \csc。这个快捷键会在命令栏运行命令 "KeywordComment":
:SpecialComment
现在按下 <Tab> 调出选择菜单来挑一个。
------------------------------------------------------------------------------
1.1.8 标签 (插件) *csupport-comm-tags*
'tags (plugin)' 子菜单可以让你从模板系统(参见 |csupport-templates-macros|)插入
预定义的宏 template system(参见 |csupport-templates-macros|)。在可视模式下,
宏会替换被标记的文本。
------------------------------------------------------------------------------
1.1.9 日期和日期+时间 *csupport-comm-date*
'date' 和 'date time' 可以由用户来定义(参见 |csupport-templates-date|)。在可视
模式下,宏会替换被标记的文本(如: 更新日期和时间)。
------------------------------------------------------------------------------
1.1.10 C 注释转 C++ 注释,反之亦然 *csupport-comm-c-cpp*
菜单项 "// xxx -> /* xxx */" 将 C++ 注释转换成 C 注释。这可以在正常模式或插入模
式的 当前行和可视模式的标记块中完成。
如果有多个 C 注释,则只有第一个会被转换:
printf ("\n"); /* one */ /* two */ /* three */
会变成
printf ("\n"); // one /* two */ /* three */
菜单项 "/* xxx */ -> // xxx" 将 C 注释转换成 C++ 注释。
------------------------------------------------------------------------------
1.2 'Statements' 菜单 *csupport-stat*
------------------------------------------------------------------------------
1.2.1 正常模式,插入模式 *csupport-stat-normal-mode*
将会插入一条空语句并适当缩进。菜单项 "if{}" 将会插入一条 if 语句:
if ( )
{
}
1.2.2 可视模式 *csupport-stat-visual-mode*
带代码块的语句和 case 标签
--------------------------------------
高亮区域
xxxxx
xxxxx
将会被以下语句之一环绕:
+----------------------------+-----------------------------+
| if ( ) | if ( ) |
| { | { |
| xxxxx | xxxxx |
| xxxxx | xxxxx |
| } | } |
| | else |
| | { |
| | } |
+----------------------------+-----------------------------+
| for ( ; ; ) | while ( ) |
| { | { |
| xxxxx | xxxxx |
| xxxxx | xxxxx |
| } | } |
+----------------------------+-----------------------------+
| do | |
| { | { |
| xxxxx | xxxxx |
| xxxxx | xxxxx |
| } | } |
| while ( ); | |
+----------------------------+-----------------------------+
| switch ( ) { |
| case : |
| break; |
| |
| case : |
| break; |
| |
| case : |
| break; |
| |
| case : |
| break; |
| |
| default: |
| break; |
| } |
+----------------------------+-----------------------------+
整个语句在插入后会进行缩进。
不带代码块的语句
--------------------------
将会插入以下语句之一
+-------------------------------+--------------------------+
| if ( ) | for ( ; ; ) |
+-------------------------------+--------------------------+
| if ( ) | while ( ) |
| else | |
+-------------------------------+--------------------------+
| case : | |
| break; | |
+-------------------------------+--------------------------+
------------------------------------------------------------------------------
1.3 'Preprocessor' 菜单 *csupport-prep*
------------------------------------------------------------------------------
1.3.1 正常模式,插入模式 *csupport-prep-normal-mode*
将会插入预处理器语句并适当缩进。
1.3.2 可视模式 *csupport-prep-visual-mode*
带代码块的语句
----------------------
高亮区域
xxxxx
xxxxx
将会被以下语句之一环绕:
+----------------------------+-----------------------------+
| #if CONDITION |
| xxxxx |
| xxxxx |
| #else /* ----- #if CONDITION ----- */ |
| |
| #endif /* ----- #if CONDITION ----- */ |
+----------------------------------------------------------+
| #ifdef CONDITION |
| xxxxx |
| xxxxx |
| #else /* ----- #ifdef CONDITION ----- */ |
| |
| #endif /* ----- #ifdef CONDITION ----- */ |
+----------------------------------------------------------+
| #ifndef CONDITION |
| xxxxx |
| xxxxx |
| #else /* ----- #ifndef CONDITION ----- */ |
| |
| #endif /* ----- #ifndef CONDITION ----- */ |
+----------------------------------------------------------+
| #ifndef INC_TEST |
| #define INC_TEST |
| xxxxx |
| xxxxx |
| #endif /* ----- #ifndef INC_TEST ----- */ |
+----------------------------------------------------------+
| #if 0 /* ----- #if 0 : If0Label_1 ----- */ |
| |
| #endif /* ----- #if 0 : If0Label_1 ----- */ |
+----------------------------------------------------------+
作为一个建议,包含防护的宏名字(如上 INC_TEST)将由文件名得来。
1.3.3 用 "#if 0 ... #endif" 封闭代码 *csupport-prep-if0*
菜单项 "#if 0 #endif" 插入行
#if 0 /* ----- #if 0 : If0Label_1 ----- */
#endif /* ----- #if 0 : If0Label_1 ----- */
在可视模式下,标记的代码块会被这些行包围。
这通常用来暂时封闭一些代码。像标签名 If0Label_1 是自动插入到代码中的。尾部的数字
是自动递增的。用户可以修改这些数字。下一个数字将会比当前缓冲区中最大的数字还要
大一。
对应的标签可以使用 vim 的星号命令(*)来搜索到。所有的标签都可以使用全局搜索,像
:g/If0Label_/ 或 :g/If0Label_\d\+/ 。所有对应的行都可以使用 :g/If0Label_/d删除。
去除包围结构 "#if 0 ... #endif"
如果光标位于这样的段落中间或者在邻近的两行之上,菜单项 'remove #if #endif' 将会
删除这个结构。原生的结构不会受到影响。
1.3.4 外部命令 *csupport-prep-ex*
有 4 个附加的外部命令可以用来插入包含语句:
外部命令 快捷键 包含
-------------------------------------------------------------------------
:IncludeStdLibrary \ps C 标准库
:IncludeC99Library \pc C99 库
:IncludeCppLibrary \+ps C++ 标准库
:IncludeCppCLibrary \+pc C 标准库 ( #include <c...> )
键入 :Inc<Tab> 来选择一个命令。现在,键入一个额外的空格和一个 <Tab> 来显示全部
列表或是键入一个空格和几个首字符以减小这个列表。
------------------------------------------------------------------------------
1.4 'Idioms' 菜单 *csupport-idioms*
------------------------------------------------------------------------------
1.4.1 'function' 项 *csupport-idioms-function*
正常模式,插入模式:
提供函数名字后,以下行(用于函数名 "f")将会插入。
void
f ( )
{
return ;
} /* ---------- end of function f ---------- */
可视模式:
Main 或 [ 静态 ] 函数: 高亮行会在新函数或 main 函数里面。
for 循环: 高亮行会放在花括号内。
1.4.2 for 循环控制 *csupport-idioms-for-loop*
菜单项 'for( x=0; ... )' 和 'for( x=n-1; ... )' 可以用来为 for 循环的正向或
反向计数写一个控制语句。这些菜单项会打开一个输入对话框
[TYPE (expand)] VARIABLE [START [END [INCR.]]] :
至少要提供循环变量名。其它参数为可选。类型被限制为以下整数数据类型:
char
int
long
long int
long long
long long int
short
short int
size_t
unsigned
unsigned char
unsigned int
unsigned long
unsigned long int
unsigned long long
unsigned long long int
unsigned short
unsigned short int
任一类型都可以通过键入全部类型名,0 个或多个字符,然后使用 <Tab> 键来补全。
如果类型名的开头是有歧义的 (如: 'uns'),可以通过提供的候选补全列表来选择。
1.4.3 'open input file' 项 *csupport-idioms-input*
'open input file' 会创建语句来打开和关闭输入文件(如: 通过文件指针 'infile')。
1.4.4 'open output file' 项 *csupport-idioms-output*
'open output file' 会创建语句来打开和关闭输出文件(如: 通过文件指针 'outfile')。
------------------------------------------------------------------------------
1.5 'Snippets' 菜单 *csupport-snippets*
------------------------------------------------------------------------------
1.5.1 代码片断
代码片断就是一小部分代码,以独立文件的形式保存在特定目录下(如: 几行代码或一个
Makefile 的完全模板)。
文件名是用于区分这些代码片断。片断目录在安装过程中创建(默认值为
$HOME/.vim/codesnippets-c)。
片断由 Snippets 子菜单下的 3 个菜单项管理。
C/C++ -> Snippets -> read code snippet
C/C++ -> Snippets -> write code snippet
C/C++ -> Snippets -> edit code snippet
创建新代码片断
如果没有标记区域,"write code snippet" 将整个缓冲区写入到一个片断文件,否则只有
标记的区域会被写入文件。
插入代码片断
从片断目录("read code snippet")选择相应的文件,插入的行会自动缩进。
编辑代码片断
这是一个正常的文本编辑。
缩进 / 不缩进
代码片断通常会在插入后缩进。为了阻止缩进,在缩进文件名后增加扩展名 "ni" 或
"noindent",如
parameter_handling.c.noindent
片断浏览器
---------------
在 GUI 下会提供一个打开文件对话框。没有 GUI 则会从命令行读取文件名。你可以通过
在你的 ~/.vimrc 中设置一个全局变量来改变这个行为。
let g:C_GuiSnippetBrowser = 'commandline'
默认值是 'gui'。
1.5.2 原型拾取 *csupport-proto*
原型拾取。
根据函数头部来做一个原型,标记函数头,选择 'Snippets -> pick up prototype'。
原型
void print_double_array ( double array[], int n, int columns, char* arrayname );
的前六行
void
print_double_array ( double array[], /* array to print */
int n, /* number of elements to print */
int columns, /* number of elements per column */
char* arrayname /* array name */
)
{
...
} /* ---------- end of function print_double_array ---------- */
产生出来,并放置在一个内部的缓冲区。
- 去掉了头部和尾部空格。
- 所有内部空格都被压缩了。
- 所有注释会被丢弃。
- 函数体尾部(如 '{')也会被去除。
- 类名和范围解析符会被去除(C++ 方法定义)。
可以拾取更多的原型并收集到同一个缓冲区。
对于 C++ 方法,命令空间的名字和类名都会被删除。(例外: 'std::')。下列前两行
std::string
ROBOT::Robot::get_name ( void )
{
return type_name;
} /* ----- end of method Robot::get_name ----- */
会得到原型
std::string get_name ( void );
代码折叠有利于原型拾取(见 |csupport-folding|)。
插入原型
随着 'Snippets -> insert prototype(s)',所有当前缓冲区中拾取的原型会被插入到
光标后。
原型缓冲区会在插入后清空。
丢弃原型
随着 'Snippets -> clear prototype(s)',原型缓冲区将会被清空。
展现原型
收集的原型列表由 'Snippets -> show prototype(s)' 展现。序号和文件名都会被显示。
如:
(1) matrix.c # double** calloc_double_matrix ( int rows, int columns );
(2) matrix.c # void free_double_matrix ( double **m );
(3) foomain.c # void foo ( );
注意。产生原型这种方式在小项目中很好。你可能想用一个像 cextract 或其它之类的
提取器。
1.5.3 代码模板 *csupport-templates-menu*
---------------------
几乎所有的菜单入口都插入代码片断或注释。所有这些东西都是从模板文件中读取,并且
可以由用户修改以满足他的需求(见 |csupport-templates| 如何使用模板系统)。
菜单项 'edit local templates' 会打开本地插件安装目录中的主模板文件。
通常是 '~/.vim/c-support/templates/Templates'。这取决于从主文件中加载的文件。
现在,修改你想改的任何文件并保存,然后点击菜单项 'reread templates' 读取文件,
来重建模板的内部表现。
菜单项 'edit global templates' 会打开系统插件安装目录中的主模板文件。(见
|csupport-system-wide|)。通常是 '$VIM./vimfiles/c-support/templates/Templates'.
模板浏览器
----------------
在 GUI 下会提供一个打开文件对话框。没有 GUI 则会从命令行读取文件名。你可以通过
在你的 ~.vimrc 中设置一个全局变量来改变这个行为:
let g:C_GuiTemplateBrowser = 'explorer'
默认值为 'gui'。 'explorer' 会打开一个文件浏览器(见帮助 |:Explore|)。使用命令
行则设置为 'commandline'。
------------------------------------------------------------------------------
1.6 'C++' 菜单 *csupport-c++*
------------------------------------------------------------------------------
1.6.1 正常模式,插入模式。 *csupport-c++-normal-mode*
将会插入一个空语句,在某些情况下会正常的缩进。菜单项 'try .. catch' 将插入
以下行:
try {
}
catch ( const &ExceptObj ) { // handle exception:
}
catch (...) { // handle exception: unspecified
}
光标将会在 try 区块。
1.6.2 可视模式。 *csupport-c++-visual-mode*
高亮区域将会被下列语句之一所环绕:
try - catch
catch
catch(...)
namespace { }
extern "C" { }
整个语句将会在插入后缩进。
1.6.3 方法实现 *csupport-c++-method-impl*
菜单项 'method implement.' 要求提供一个方法名。如果是第一次调用,你将会看到一个
范围解析符。如果你指定了范围,它将会在下次调用时乃至。如果你使用了其中的一个
菜单项来产生一个类(见 |csupport-templates|),这个范围将会被提取并用于下一个
方法。
1.6.4 外部命令 *csupport-c++-ex*
一共有 4 个外部命令可以用来插入 include 语句。见 |csupport-prep-ex|.
------------------------------------------------------------------------------
1.7 'Run' 菜单 *csupport-run*
------------------------------------------------------------------------------
1.7.1 最小 MAKE 功能 *csupport-run-buffer*
'Run' 菜单为单文件项目提供了一个最小 make 功能(如: 在教学中):
保存和编译
'save and compile' 保存缓冲区,以给定的选项运行编译器
(见 |csupport-custom-glob-vars|)。
如果编译器报告了错误或警告,会打开一个错误显示窗口。这时,Quickfix 命令可以用于
跳转到一个错误产生的位置。
请考虑在你的 ~/.vimrc 文件中使用类似映射
map <silent> <F7> <Esc>:cprevious<CR>
map <silent> <F8> <Esc>:cnext<CR>
跳过错误的位置,便导航更加容易。错误列表和错误位置会在源文件缓冲区中保持同步。
目标文件的扩展名可以在 ~.vimrc 中设置:
let g:C_ObjExtension = '.obj'
默认为 '.o'('.obj' 适用于 Windows)。
链接
'link' 从当前缓冲区创建一个可执行程序。如果缓冲区没有保存,或者没有可用目标文件
或者目标文件早于源文件,则首先执行 'save and compile'。
只有当前缓冲区里包含一个 main 函数,才会尝试进行链接。
编译器 / 链接器的行为取决于对选项的赋值,选项描述见 |csupport-custom-glob-vars|
(第三组)。
运行
'run' 执行与当前缓冲区名字相同的可执行程序。如果缓冲区没有保存,或都没有可执行
文件,或者可执行程序早于源文件,则首先执行 'save and compile' 和 'link'。
可执行程序的扩展名可以在 ~.vimrc 中设置:
let g:C_ExeExtension = '.exe'
默认是空字符串。
1.7.2 命令行参数 *csupport-run-cmdline-args*
菜单项 'command line arguments' 调用一个输入对话框来请求命令行参数。这些参数会
被转发到由菜单项 'run' 运行的程序。除非你改变,否则参数会一直保留。
对于第一个并且是唯一的参数时,将会进行文件名扩展(使用 <Tab> 键)。由于 Vim
输入功能的限制,只有输入的第一个字符串才会被扩展。如果要扩展两个或更多的文件名
,可以按倒序来指定它们: 输入最后一个文件名的首字符并扩展,回到输入的起点,输入
倒数第二个文件名的开始并扩展它。
该参数属于当前的缓冲区(也就是说,每个缓冲区都能有自己的参数)。
如果缓冲区通过 "save as" 得到一个新名字,参数将会属于使用新名字的缓冲区。
命令行参数可以带有管道符和重定向符:
11 22 | sort -rn | head -10 > out
警告: 如果你想通过再次调用这个菜单项来查看当前参数,请确保离开时使用回车(而
不是 Esc !)。由于 Vim 函数内部的限制,回车保留参数,Esc 会丢弃它们。
1.7.3 运行 make *csupport-run-make*
菜单项 'make' 运行外部的 make 程序。如果编译器或链接器在 make 过程中报告错误或
警告,将会打开一个错误窗口。Quickfix 命令可以用于跳转到一个错误位置。
当位于一个 makefile 中,快捷键 \rm,\rmc,和 \rma 都是可用的(见
|csupport-usage-vim|)。
代码片断集合中包含了一个简单的 makefile,可以简单适用于小项目。
1.7.4 运行可执行程序 *csupport-run-make-run*
菜单项 'executable to run' 要求提供由 make 创建的可执行程序的名字。如果给定的
名字不为空,可执行程序将由菜单项 'run'(\rr,C-F9)来运行。
调用 'excutable to run' 时删除名字将回到默认行为(见 |csupport-run-buffer|)。
1.7.5 运行 make clean *csupport-run-make-clean*
菜单项 'make' 使用标准目标 'clean' 运行外部 make 程序 'clean'。
1.7.6 make 的命令行参数 *csupport-run-make-args*
菜单项 'command line arguments for make' 调用一个输入对话框来请求 make 的命令行
参数。当 make 被菜单项 'make' 调用时,这些参数将被转发。
对于第一个并且是唯一的参数,文件名展开是可用的(使用 <Tab>)。
1.7.7 SPLINT *csupport-run-splint*
Splint 是一个 C 程序静态检查工具(见 http://www.splint.org)。
当然它必须是已安装的以便于在 Vim 中使用。菜单项 'Run->splint' 将会通过 splint
来运行当前缓冲区。
如果 splint 报错,将会打开一个错误窗口,Quickfix 命令可以用于跳转到错误位置。
为了更容易地导航,参见 'SAVE AND COMPILE' |csupport-run-buffer| 底下的提示。
Splint 有很多选项。意味着将这些选项保存到一个选项文件(~/.splintrc)是最好的
办法。对于快速尝试,你可以使用菜单项 'Run->cmd. line arg. for splint' 来指定
一些缓冲区相关选项。
当 Vim 启动时,这个插件将检测 Splint 是否为可执行程序,如果不是,该菜单项将不会
显示。
1.7.8 CODECHECK *csupport-run-codecheck*
CodeCheck (TM) 是一个由 Abraxas Software, Inc. (www.abraxas-software.com) 制作
的商业代码分析工具。
当然它必须是已安装的以便于在 Vim 中使用。菜单项 item 'Run->CodeCheck' 将会通过
CodeCheck 来运行当前缓冲区。
如果 CodeCheck 报错,将会打开一个错误窗口,Quickfix 命令可以用于跳转到错误位置。
为了更容易地导航,参见 'SAVE AND COMPILE' |csupport-run-buffer| 底下的提示。
CodeCheck 有很多选项。对于快速尝试,你可以使用菜单项
'Run->cmd. line arg. for CodeCheck' 来指定一些缓冲区相关选项。
CodeCheck 会使用默认选项启动(见 |csupport-custom-glob-vars|)。默认选项可以
通过在 ~/.vimrc 中设置一个全局变量来覆盖。如:
let g:C_CodeCheckOptions = "-K13 -Rmeyers"
默认的可执行程序名字为 'check'。在不同的平台会使用一些其它的名字。可以在
~/.vimrc 中设置一个全局变量来修改这个名字,如:
let g:C_CodeCheckExeName = "chknt.exe"
当 Vim 启动时,这个插件将检查 CodeCheck 是否为可执行程序,如果不是,该菜单项将
不会显示。
1.7.9 INDENT *csupport-run-indent*
The formatter 'indent' can be run over the whole buffer. Before formatting a
buffer this buffer will be saved to disk and you will be asked for a
confirmation.
Indent has many options. These are kept in the file '.indent.pro' in your home
directory. See the indent manual for more information.
1.7.10 HARDCOPY *csupport-run-hardcopy*
Generates a PostScript file from the whole buffer or from a marked region.
On a Windows system a printer dialog is displayed.
The hardcopy goes to the current working directory. If the buffer contains
documentation or other material from non-writable directories the hardcopy
goes to the HOME directory. The output destination will be shown in a message.
The print header contains date and time for the current locale. The definition
used is
let s:C_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} Page %N"
The current locale can be overwritten by changing the language, e.g.
:language C
or by setting a global variable in the file ~/.vimrc , e.g. :
let g:C_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} SEITE %N"
See :h printheader and :h strftime() for more details.
1.7.11 REBUILD TEMPLATES *csupport-run-templates*
After editing one or more template files a click on this item rereads the
template files and rebuilds all templates.
1.7.12 XTERM SIZE *csupport-run-xterm*
The size of the xterm used for running a program (below) can be set by this
menu item. The default is 80 columns with 24 lines.
This feature is not available under Windows.
1.7.13 OUTPUT REDIRECTION *csupport-run-output*
Running a program can be done in one of three ways:
(1) Run the program from the gVim command line.
This is for interactive programs with little input and output.
(2) Run the program and direct the output into a window with name "C-Output".
The buffer and its content will disappear when the window is closed and
reused otherwise.
This is for non-interactive programs with little to very much output.
You have unlimited line length, regex search, navigation, ...
The tabstop value will be set to 8 for "C-Output".
(3) Run the program in an xterm.
The output method can be chosen from the menu item 'Run->output: ...'.
This menu has three states:
output: VIM->buffer->xterm
output: BUFFER->xterm->vim
output: XTERM->vim->buffer
The first (uppercase) item shows the current method. The default is 'vim'.
This can be changed by setting the variable g:C_OutputGvim to another value.
Possible values are 'vim', 'buffer' and 'xterm' .
The xterm defaults can be set in ~/.vimrc by the variable g:C_XtermDefaults .
The default is "-fa courier -fs 12 -geometry 80x24" :
font name : -fa courier
font size : -fs 12
terminal size : -geometry 80x24
See 'xterm -help' for more options. Xterms are not available under Windows.
------------------------------------------------------------------------------
1.8 'help' *csupport-help*
------------------------------------------------------------------------------
Plugin help
-----------
The root menu item 'help (plugin)' shows this plugin help in a help window.
The help tags must have been generated with
:helptags ~/.vim/doc
The hotkey is \hp (for "help plugin").
Displaying a manual
-------------------
The root menu item 'show manual' shows the manual for the word under the
cursor. If there is more than one manual a selection list will be presented.
If there is no word under the cursor you can type in a name. An interface to
the on-line reference manuals must be installed (usually man(1) for
Linux/Unix, see|csupport-custom-glob-vars|).
The hotkey is \hm (for "help manual").
==============================================================================
2. USAGE WITHOUT GUI (Vim) *csupport-usage-vim*
==============================================================================
The frequently used constructs can be inserted with key mappings. The
mappings are also described in the document c-hot-keys.pdf (reference card,
part of this package).
Hint: Typing speed matters. The combination of a leader ('\') and the
following character(s) will only be recognized for a short time.
The insert mode mappings start with ` (backtick).
Legend: (i) insert mode, (n) normal mode, (v) visual mode
-- Help ---------------------------------------------------------------
\hm show manual for word under the cursor (n,i)