]> git.madduck.net Git - etc/vim.git/blob - .vim/snippets/c.snippets

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

89b81ba62d26b69b6885e319b1b08353f651d04f
[etc/vim.git] / .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 # #include <...>
9 snippet inc
10         #include <${1:stdio}.h>${2}
11 # #include "..."
12 snippet Inc
13         #include "${1:`Filename("$1.h")`}"${2}
14 # #ifndef ... #define ... #endif
15 snippet Def
16         #ifndef $1
17         #define ${1:SYMBOL} ${2:value}
18         #endif${3}
19 snippet def
20         #define 
21 snippet ifdef
22         #ifdef ${1:FOO}
23                 ${2:#define }
24         #endif
25 snippet #if
26         #if ${1:FOO}
27                 ${2}
28         #endif
29 # Header Include-Guard
30 # (the randomizer code is taken directly from TextMate; it could probably be
31 # cleaner, I don't know how to do it in vim script)
32 snippet once
33         #ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system("/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'"))`}
34
35         #define $1
36
37         ${2}
38
39         #endif /* end of include guard: $1 */
40 # If Condition
41 snippet if
42         if (${1:/* condition */}) {
43                 ${2:/* code */}
44         }
45 snippet el
46         else {
47                 ${1}
48         }
49 # Tertiary conditional
50 snippet t
51         ${1:/* condition */} ? ${2:a} : ${3:b}
52 # Do While Loop
53 snippet do
54         do {
55                 ${2:/* code */}
56         } while (${1:/* condition */});
57 # While Loop
58 snippet wh
59         while (${1:/* condition */}) {
60                 ${2:/* code */}
61         }
62 # For Loop
63 snippet for
64         for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
65                 ${4:/* code */}
66         }
67 # Custom For Loop
68 snippet forr
69         for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
70                 ${5:/* code */}
71         }
72 # Function
73 snippet fun
74         ${1:void} ${2:function_name}(${3})
75         {
76                 ${4:/* code */}
77         }
78 # Function Declaration
79 snippet fund
80         ${1:void} ${2:function_name}(${3});${4}
81 # Typedef
82 snippet td
83         typedef ${1:int} ${2:MyCustomType};${3}
84 # Struct
85 snippet st
86         struct ${1:`Filename('$1_t', 'name')`} {
87                 ${2:/* data */}
88         }${3: /* optional variable list */};${4}
89 # Typedef struct
90 snippet tds
91         typedef struct ${2:_$1 }{
92                 ${3:/* data */}
93         } ${1:`Filename('$1_t', 'name')`};
94 # Typdef enum
95 snippet tde
96         typedef enum {
97                 ${1:/* data */}
98         } ${2:foo};
99 # printf
100 # unfortunately version this isn't as nice as TextMates's, given the lack of a
101 # dynamic `...`
102 snippet pr
103         printf("${1:%s}\n"${2});${3}
104 # fprintf (again, this isn't as nice as TextMate's version, but it works)
105 snippet fpr
106         fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
107 snippet .
108         [${1}]${2}
109 snippet un
110         unsigned