mirror of
https://github.com/gryf/snipmate.vim.git
synced 2025-12-19 20:38:05 +01:00
Completely replaced command-based snippets with a new, easier to read/maintain syntax. Also added a python script to make it easier to migrate.
This commit is contained in:
88
snippets/c.snippets
Normal file
88
snippets/c.snippets
Normal file
@@ -0,0 +1,88 @@
|
||||
# main()
|
||||
snippet main
|
||||
int main (int argc, char const* argv[])
|
||||
{
|
||||
${1}
|
||||
return 0;
|
||||
}
|
||||
# #include <...>
|
||||
snippet inc
|
||||
#include <${1:stdio}.h>${2}
|
||||
# #include "..."
|
||||
snippet Inc
|
||||
#include "${1:`Filename("$1.h")`}"${2}
|
||||
# #ifndef ... #define ... #endif
|
||||
snippet def
|
||||
#ifndef $1
|
||||
#define ${1:SYMBOL} ${2:value}
|
||||
#endif${3}
|
||||
# Header Include-Guard
|
||||
# (the randomizer code is taken directly from TextMate; it could probably be
|
||||
# cleaner, I don't know how to do it in vim script)
|
||||
snippet once
|
||||
#ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system("/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'"))`}
|
||||
|
||||
#define $1
|
||||
|
||||
${2}
|
||||
|
||||
#endif /* end of include guard: $1 */
|
||||
# If Condition
|
||||
snippet if
|
||||
if (${1:/* condition */}) {
|
||||
${2:/* code */}
|
||||
}
|
||||
snippet el
|
||||
else {
|
||||
${1}
|
||||
}
|
||||
# Tertiary conditional
|
||||
snippet t
|
||||
${1:/* condition */} ? ${2:a} : ${3:b}
|
||||
# Do While Loop
|
||||
snippet do
|
||||
do {
|
||||
${2:/* code */}
|
||||
} while (${1:/* condition */});
|
||||
# While Loop
|
||||
snippet wh
|
||||
while (${1:/* condition */}) {
|
||||
${2:/* code */}
|
||||
}
|
||||
# For Loop
|
||||
snippet for
|
||||
for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
||||
${4:/* code */}
|
||||
}
|
||||
# Custom For Loop
|
||||
snippet forr
|
||||
for (${1:i} = 0; ${2:$1 < 10}; $1${3:++}) {
|
||||
${4:/* code */}
|
||||
}
|
||||
# Function
|
||||
snippet fun
|
||||
${1:void} ${2:function_name} (${3})
|
||||
{
|
||||
${4:/* code */}
|
||||
}
|
||||
# Typedef
|
||||
snippet td
|
||||
typedef ${1:int} ${2:MyCustomType};
|
||||
# Struct
|
||||
snippet st
|
||||
struct ${1:`Filename('$1_t', 'name')`} {
|
||||
${2:/* data */}
|
||||
}${3: /* optional variable list */};${4}
|
||||
# Typedef struct
|
||||
snippet tds
|
||||
typedef struct ${2:$1 }{
|
||||
${3:/* data */}
|
||||
} ${1:`Filename('$1_t', 'name')`};
|
||||
# printf
|
||||
# unfortunately version this isn't as nice as TextMates's, given the lack of a
|
||||
# dynamic `...`
|
||||
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}
|
||||
Reference in New Issue
Block a user