vim-snippets/snippets/c.snippets

158 lines
2.9 KiB
Plaintext
Raw Normal View History

2012-08-28 14:41:46 -04:00
## Main
# main
snippet main
int main(int argc, const char *argv[])
{
${1}
return 0;
}
2012-08-28 14:41:46 -04:00
# main(void)
snippet mainn
int main(void)
{
${1}
return 0;
}
2012-08-28 14:41:46 -04:00
##
## Preprocessor
# #include <...>
snippet inc
#include <${1:stdio}.h>${2}
# #include "..."
snippet Inc
#include "${1:`Filename("$1.h")`}"${2}
2012-08-28 14:41:46 -04:00
# ifndef...define...endif
snippet ndef
#ifndef $1
#define ${1:SYMBOL} ${2:value}
#endif${3}
2012-08-28 14:41:46 -04:00
# define
snippet def
#define
2012-08-28 14:41:46 -04:00
# ifdef...endif
snippet ifdef
#ifdef ${1:FOO}
${2:#define }
#endif${3}
2012-08-28 14:41:46 -04:00
# if
snippet #if
#if ${1:FOO}
${2}
2012-08-28 14:41:46 -04:00
#endif
# header include guard
snippet once
#ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
#define $1
${2}
#endif /* end of include guard: $1 */
2012-08-28 14:41:46 -04:00
##
## Control Statements
# if
snippet if
if (${1:/* condition */}) {
${2:/* code */}
}${3}
2012-08-28 14:41:46 -04:00
# else
snippet el
else {
${1}
2012-08-28 14:41:46 -04:00
}${3}
# else if
2012-08-28 13:34:24 -04:00
snippet elif
else if (${1:/* condition */}) {
${2:/* code */}
}${3}
2012-08-28 14:41:46 -04:00
# ternary
snippet t
${1:/* condition */} ? ${2:a} : ${3:b}
2012-08-28 14:41:46 -04:00
##
## Loops
# for
snippet for
for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
${4:/* code */}
}${5}
2012-08-28 14:41:46 -04:00
# for (custom)
snippet forr
for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
${5:/* code */}
}${6}
2012-08-28 14:41:46 -04:00
# while
snippet wh
while (${1:/* condition */}) {
${2:/* code */}
}${3}
# do... while
snippet do
do {
${2:/* code */}
} while (${1:/* condition */});${3}
##
## Functions
# function definition
snippet fun
${1:void} ${2:function_name}(${3})
{
${4:/* code */}
}${5}
2012-08-28 14:41:46 -04:00
# function declaration
snippet fund
${1:void} ${2:function_name}(${3});${4}
2012-08-28 14:41:46 -04:00
##
## Types
# typedef
snippet td
typedef ${1:int} ${2:MyCustomType};${3}
2012-08-28 14:41:46 -04:00
# struct
snippet st
struct ${1:`Filename('$1_t', 'name')`} {
${2:/* data */}
}${3: /* optional variable list */};${4}
2012-08-28 14:41:46 -04:00
# typedef struct
snippet tds
typedef struct ${2:_$1 }{
${3:/* data */}
} ${1:`Filename('$1_t', 'name')`};${4}
2012-08-28 14:41:46 -04:00
# typedef enum
snippet tde
typedef enum {
${1:/* data */}
} ${2:foo};${3}
2012-08-28 14:41:46 -04:00
##
## Input/Output
# printf
snippet pr
printf("${1:%s}\n"${2});${3}
# fprintf (again, this isn't as nice as TextMate's version, but it works)
snippet fpr
fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
2012-08-28 14:41:46 -04:00
##
## Miscellaneous
# This is kind of convenient
snippet .
[${1}]${2}
# GPL
snippet gpl
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) ${1:Author}, `strftime("%Y")`
*/
${2}