forked from yangyangwithgnu/use_vim_as_ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc.snippets
executable file
·489 lines (380 loc) · 7.25 KB
/
c.snippets
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
## Main
# main
snippet main
int main(int argc, const char *argv[])
{
${0}
return 0;
}
endsnippet
# main(void)
snippet mainn
int main(void)
{
${0}
return 0;
}
endsnippet
##
## Preprocessor
# #include <...>
snippet inc
#include <${1:stdio}.h>
endsnippet
# #include "..."
snippet Inc
#include "${1:`vim_snippets#Filename("$1.h")`}"
endsnippet
# ifndef...define...endif
snippet ndef
#ifndef $1
#define ${1:SYMBOL} ${2:value}
#endif /* ifndef $1 */
endsnippet
# define
snippet def
#define
endsnippet
# ifdef...endif
snippet ifdef
#ifdef ${1:FOO}
${2:#define }
#endif
endsnippet
# if
snippet #if
#if ${1:FOO}
${0:${VISUAL}}
#endif
endsnippet
# header include guard
snippet once
#ifndef ${1:`toupper(vim_snippets#Filename('$1_H', 'UNTITLED_H'))`}
#define $1
${0}
#endif /* end of include guard: $1 */
endsnippet
# Disable C++ name mangling in C headers
snippet nocxx
#ifdef __cplusplus
extern "C" {
#endif
${0}
#ifdef __cplusplus
} /* extern "C" */
#endif
endsnippet
##
## Control Statements
# if
snippet if
if(${1:true}){
${0:${VISUAL}}
}
endsnippet
snippet ife
if (${1:true}) {
${2:${VISUAL}}
} else {
${0}
}
endsnippet
# else
snippet el
else {
${0:${VISUAL}}
}
endsnippet
# else if
snippet elif
else if (${1:true}) {
${0:${VISUAL}}
}
endsnippet
# ifi
snippet ifi
if (${1:true}) ${0};
endsnippet
# ternary
snippet t
${1:/* condition */} ? ${2:a} : ${3:b}
endsnippet
# switch
snippet switch
switch (${1:/* variable */}) {
case ${2:/* variable case */}:
${3}
${4:break;}${5}
default:
${6}
}
endsnippet
# switch without default
snippet switchndef
switch (${1:/* variable */}) {
case ${2:/* variable case */}:
${3}
${4:break;}${5}
}
endsnippet
# case
snippet case
case ${1:/* variable case */}:
${2}
${3:break;}
endsnippet
snippet ret
return ${0};
endsnippet
##
## Loops
# for
snippet for
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
${4}
}
endsnippet
# for (custom)
snippet forr
for (int ${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
${5}
}
endsnippet
# while
snippet wh
while (${1:/* condition */}) {
${0:${VISUAL}}
}
endsnippet
# do... while
snippet do
do {
${0:${VISUAL}}
} while (${1:/* condition */});
endsnippet
##
## Functions
# function definition
snippet fun
${1:void} ${2:function_name}(${3})
{
${4}
}
endsnippet
# function definition with zero parameters
snippet fun0
${1:void} ${2:function_name}()
{
${3}
}
endsnippet
# function definition with Doxygen documentation
snippet dfun0
/*! \brief ${1:Brief function description here}
*
* ${2:Detailed description of the function}
*
* \return ${3:Return parameter description}
*/
${4:void} ${5:function_name}()
{
${6}
}
endsnippet
# function definition with one parameter
snippet fun1
${1:void} ${2:function_name}(${3:Type} ${4:Parameter})
{
${5}
}
endsnippet
# function definition with one parameter with Doxygen documentation
snippet dfun1
/*! \brief ${1:Brief function description here}
*
* ${2:Detailed description of the function}
*
* \param $3 ${4:Parameter description}
* \return ${5:Return parameter description}
*/
${6:void} ${7:function_name}(${8:Type} ${3:Parameter})
{
${9}
}
endsnippet
# function definition with two parameters
snippet fun2
${1:void} ${2:function_name}(${3:Type} ${4:Parameter}, ${5:Type} ${6:Parameter})
{
${7}
}
endsnippet
# function definition with two parameters with Doxygen documentation
snippet dfun2
/*! \brief ${1:Brief function description here}
*
* ${2:Detailed description of the function}
*
* \param $3 ${4:Parameter description}
* \param $5 ${6:Parameter description}
* \return ${7:Return parameter description}
*/
${8:void} ${9:function_name}(${10:Type} ${3:Parameter}, ${11:Type} ${5:Parameter})
{
${12}
}
endsnippet
# function definition with three parameters
snippet fun3
${1:void} ${2:function_name}(${3:Type} ${4:Parameter}, ${5:Type} ${6:Parameter}, ${7:Type} ${8:Parameter})
{
${9}
}
endsnippet
# function definition with three parameters with Doxygen documentation
snippet dfun3
/*! \brief ${1:Brief function description here}
*
* ${2:Detailed description of the function}
*
* \param $3 ${4:Parameter description}
* \param $5 ${6:Parameter description}
* \param $7 ${8:Parameter description}
* \return ${9:Return parameter description}
*/
${10:void} ${11:function_name}(${12:Type} ${3:Parameter}, ${13:Type} ${5:Parameter}, ${14:Type} ${7:Parameter})
{
${15}
}
endsnippet
# function declaration
snippet fund
${1:void} ${2:function_name}(${3});
endsnippet
##
## Types
# typedef
snippet td
typedef ${1:int} ${2:MyCustomType};
endsnippet
# struct
snippet st
/*! \struct $1
* \brief ${3:Brief struct description}
*
* ${4:Detailed description}
*/
struct ${1:`vim_snippets#Filename('$1_t', 'name')`} {
${2:Data} /*!< ${4:Description} */
}${5: /* optional variable list */};
endsnippet
# typedef struct
snippet tds
/*! \struct $2
* \brief ${5:Brief struct description}
*
* ${6:Detailed description}
*/
typedef struct ${2:_$1 }{
m_${3:Data} /*!< ${4:Description} */
} ${1:`vim_snippets#Filename('$1_t', 'name')`};
endsnippet
snippet enum
/*! \enum $1
*
* ${2:Detailed description}
*/
enum ${1:name} { ${0} };
endsnippet
# typedef enum
snippet tde
/*! \enum $2
*
* ${4:Detailed description}
*/
typedef enum {
${1:Data} /*!< ${3:Description} */
} ${2:foo};
endsnippet
##
## Input/Output
# printf
snippet pr
printf("${1:%s}\n"${2});
endsnippet
# fprintf (again, this isn't as nice as TextMate's version, but it works)
snippet fpr
fprintf(${1:stderr}, "${2:%s}\n"${3});
endsnippet
snippet prd
printf("${1:} = %d\n", $1);
endsnippet
snippet prf
printf("${1:} = %f\n", $1);
endsnippet
snippet prx
printf("${1:} = %${2}\n", $1);
endsnippet
# getopt
snippet getopt
int choice;
while (1){
static struct option long_options[] =
{
/* Use flags like so:
{"verbose", no_argument, &verbose_flag, 'V'}*/
/* Argument styles: no_argument, required_argument, optional_argument */
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
${1}
{0,0,0,0}
};
int option_index = 0;
/* Argument parameters:
no_argument: " "
required_argument: ":"
optional_argument: "::" */
choice = getopt_long( argc, argv, "vh",
long_options, &option_index);
if (choice == -1)
break;
switch( choice ){
case 'v':
${2}
break;
case 'h':
${3}
break;
case '?':
/* getopt_long will have already printed an error */
break;
default:
/* Not sure how to get here... */
return EXIT_FAILURE;
}
}
/* Deal with non-option arguments here */
if ( optind < argc ){
while ( optind < argc ){
${0}
}
}
endsnippet
##
# TODO section
snippet todo
/*! TODO: ${1:Todo description here}
* \todo $1
*/
endsnippet
## Miscellaneous
# This is kind of convenient
snippet .
[${1}]
endsnippet
snippet b "bracket" i
(${1:${VISUAL}})${2}
endsnippet
snippet g "square" i
[${1}]${2}
endsnippet