]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/snippets/c.snippets
Add CoC config
[rbdr/dotfiles] / vim / snippets / c.snippets
1 # main()
2 snippet main
3 int main(int argc, const char *argv[])
4 {
5 ${1}
6 return 0;
7 }
8 snippet mainn
9 int main(void)
10 {
11 ${1}
12 return 0;
13 }
14 # #include <...>
15 snippet inc
16 #include <${1:stdio}.h>${2}
17 # #include "..."
18 snippet Inc
19 #include "${1:`Filename("$1.h")`}"${2}
20 # #ifndef ... #define ... #endif
21 snippet Def
22 #ifndef $1
23 #define ${1:SYMBOL} ${2:value}
24 #endif${3}
25 snippet def
26 #define
27 snippet ifdef
28 #ifdef ${1:FOO}
29 ${2:#define }
30 #endif
31 snippet #if
32 #if ${1:FOO}
33 ${2}
34 #endif
35 # Header Include-Guard
36 snippet once
37 #ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
38
39 #define $1
40
41 ${2}
42
43 #endif /* end of include guard: $1 */
44 # If Condition
45 snippet if
46 if (${1:/* condition */}) {
47 ${2:/* code */}
48 }
49 snippet el
50 else {
51 ${1}
52 }
53 # Ternary conditional
54 snippet t
55 ${1:/* condition */} ? ${2:a} : ${3:b}
56 # Do While Loop
57 snippet do
58 do {
59 ${2:/* code */}
60 } while (${1:/* condition */});
61 # While Loop
62 snippet wh
63 while (${1:/* condition */}) {
64 ${2:/* code */}
65 }
66 # For Loop
67 snippet for
68 for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
69 ${4:/* code */}
70 }
71 # Custom For Loop
72 snippet forr
73 for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
74 ${5:/* code */}
75 }
76 # Function
77 snippet fun
78 ${1:void} ${2:function_name}(${3})
79 {
80 ${4:/* code */}
81 }
82 # Function Declaration
83 snippet fund
84 ${1:void} ${2:function_name}(${3});${4}
85 # Typedef
86 snippet td
87 typedef ${1:int} ${2:MyCustomType};${3}
88 # Struct
89 snippet st
90 struct ${1:`Filename('$1_t', 'name')`} {
91 ${2:/* data */}
92 }${3: /* optional variable list */};${4}
93 # Typedef struct
94 snippet tds
95 typedef struct ${2:_$1 }{
96 ${3:/* data */}
97 } ${1:`Filename('$1_t', 'name')`};
98 # Typdef enum
99 snippet tde
100 typedef enum {
101 ${1:/* data */}
102 } ${2:foo};
103 # printf
104 # unfortunately version this isn't as nice as TextMates's, given the lack of a
105 # dynamic `...`
106 snippet pr
107 printf("${1:%s}\n"${2});${3}
108 # fprintf (again, this isn't as nice as TextMate's version, but it works)
109 snippet fpr
110 fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
111 # This is kind of convenient
112 snippet .
113 [${1}]${2}