-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathc.snip
309 lines (257 loc) · 5.55 KB
/
c.snip
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
# Control structures {{{
snippet if
options head
abbr if () {}
if (${1:#:condition}) {
${0:TARGET}
}
# No head option in else/elseif so it can be expanded after "}"
snippet else
abbr else {}
else {
${0:TARGET}
}
snippet elseif
abbr else () {}
else if (${1:#:condition}) {
${0:TARGET}
}
snippet ifelse
options head
abbr if () {} else {}
if (${1:#:condition}) {
${2:TARGET}
} else {
${3}
}
snippet for
options head
abbr for () {}
for (${1:int} ${2:i} = ${3:0}; $2 < ${4}; $2++) {
${0:#:TARGET}
}
# Counter based for's (don't ask for the type or count start)
snippet fori
options head
abbr for (int x;...; x++) {}
for (int ${1:i} = 0; $1 < ${2}; $1++) {
${0:#:TARGET}
}
# For reverse counter
snippet forri
options head
abbr for (int x; ...; x--) {}
for (int ${1:i} = ${2}; $1 >= 0; $1--) {
${0:#:TARGET}
}
snippet while
options head
abbr while () {}
while (${1:#:condition}) {
${0:TARGET}
}
snippet do_while
options head
alias do
do {
${0:TARGET:code}
} while (${1:#:condition});
snippet switch
options head
abbr switch () {}
switch (${1:#:var}) {
case ${2:#:val}:
${0:TARGET}
break;
}
snippet case
options head
abbr case: break;
case ${1}:
${0}
break;
# Ternary conditional operator
snippet conditional
(${1:#:condition}) ? ${2:#:a} : ${3:#:b}
# }}}
# Definition bodies {{{
snippet function
options head
alias func
abbr func() {}
${1:void} ${2:#:func_name}(${3:void}) {
${0:TARGET}
}
snippet struct
options head
abbr struct {}
struct ${1:#:name} {
${0:TARGET:data}
};
# Typedef struct
snippet struct_typedef
options head
typedef struct ${1:#:name} {
${0:TARGET:data}
};
snippet enum
options head
abbr enum {}
enum ${1:#:name} {
${0:TARGET}
};
# hard-tab is necessary; C indent doesn't support this.
snippet main
options head
int main(int argc, char* argv[])
{
${0:TARGET}
return 0;
}
snippet helloworld
options head
#include <stdio.h>
int main(int argc, char* argv[])
{
puts("hello, world!");
return 0;
}
# }}}
# Preprocessing directives {{{
# #include <...>
snippet inc
options head
alias #inc, #include
#include <${1:stdio}.h>
# #include "..."
snippet inc2
options head
alias #inc2, #include2
#include "${1}.h"
snippet #if
options head
#if ${1}
${0}
#endif
snippet ifdef
options head
alias #ifdef
abbr #ifdef ... #endif
#ifdef ${1:#:SYMBOL}
${0}
#endif
snippet ifndef
options head
alias #ifndef
abbr #ifndef ... #define ... #endif
#ifndef $1
#define ${1:#:SYMBOL}
#endif${0}
# This snippet used the placeholder instead of a trailing space
snippet def
options head
alias #def, #define
#define ${1}
# Include-Guard
snippet once
options head
alias include-guard
abbr #ifndef ... #define ... #endif
#ifndef ${1:#:SYMBOL}
#define $1
${0:TARGET}
#endif /* end of include guard */
# }}}
# Built-in function calls {{{
snippet printf
abbr printf("...\n", ...);
printf("${1}\n"${2});
snippet scanf
abbr scanf("...", ...);
scanf("${1}", ${2});
snippet fprintf
abbr fprintf(..., "...\n", ...);
fprintf(${1:stderr}, "${2}\n"${3});
snippet fopen
abbr fopen("...", "...");
fopen("${1:PATH}", "${2:MODE}");
${0:TARGET}
fclose(${3:FD});
snippet fgets
abbr fgets(row, length, file);
fgets(${0:ROW}, ${1:LENGTH}, ${2:stdin});
snippet fscanf
abbr fscanf(file, "...", ...);
fscanf(${1:stdin}, "${2}", ${3});
snippet fwrite
abbr fwrite(......, file)
fwrite(${1:ARRAY}, sizeof(${2:TYPE}), ${3:N_MEMBERS}, ${4:FILE})
snippet fread
abbr fread(......, file)
fread(${1:ARRAY}, sizeof(${2:TYPE}), ${3:N_MEMBERS}, ${4:FILE})
snippet memcpy
abbr memcpy(dest, src, nbytes)
memcpy(${1:DEST}, ${2:SRC}, ${3:NBYTES})
snippet malloc
abbr malloc(size)
($2 *)malloc(${1:N_MEMBERS} * sizeof(${2:TYPE}));
${0}
free(${3:MEM});
snippet calloc
abbr calloc(n, size)
($2 *)calloc(${1:N_MEMBERS}, sizeof(${2:TYPE}));
${0}
free(${3:MEM});
snippet realloc
abbr realloc(old, size)
($3 *)realloc(${1:OLD}, ${2:N_MEMBERS} * sizeof(${3:TYPE}));
${0}
snippet seed_rand
srand(time(NULL));
# }}}
# Built-in operators and alias {{{
snippet typedef
typedef ${1:#:base_type} ${2:#:custom_type};
snippet sizeof
alias size
sizeof(${0:TARGET})
snippet sizeof_array
alias array_size
(sizeof(${1:#:array}) / sizeof(*($1)))
snippet _Static_assert
alias _static_assert
options head
_Static_assert(${1:#:condition}, ${2:#:message});
snippet static_assert
options head
static_assert(${1:#:condition}, ${2:#:message});
snippet _Generic
alias generic, select
_Generic(${1:#:expression}, ${2:#:association-list})
snippet va_list
options head
abbr va_start(va_list, last_arg); ... ; va_end()
va_list ${1:ap};
va_start($1, ${2:LAST_ARG});
${0}
va_end($1);
# }}}
# Comments {{{
snippet comment
alias /*
/* ${1:#:comment} */
${0}
snippet doxy
abbr /** @brief ...
options head
/**
* @brief ${1:function description}
*
* @details ${2:detailed description}
*
* @param ${3:param}
*
* @return ${4:return type}
*/
# }}}
# vim: fdm=marker