c.snippets 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #define $1
  35. ${2}
  36. #endif /* end of include guard: $1 */
  37. # If Condition
  38. snippet if
  39. if (${1:/* condition */}) {
  40. ${2:/* code */}
  41. }
  42. snippet el
  43. else {
  44. ${1}
  45. }
  46. # Tertiary conditional
  47. snippet t
  48. ${1:/* condition */} ? ${2:a} : ${3:b}
  49. # Do While Loop
  50. snippet do
  51. do {
  52. ${2:/* code */}
  53. } while (${1:/* condition */});
  54. # While Loop
  55. snippet wh
  56. while (${1:/* condition */}) {
  57. ${2:/* code */}
  58. }
  59. # For Loop
  60. snippet for
  61. for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
  62. ${4:/* code */}
  63. }
  64. # Custom For Loop
  65. snippet forr
  66. for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
  67. ${5:/* code */}
  68. }
  69. # Function
  70. snippet fun
  71. ${1:void} ${2:function_name}(${3})
  72. {
  73. ${4:/* code */}
  74. }
  75. # Function Declaration
  76. snippet fund
  77. ${1:void} ${2:function_name}(${3});${4}
  78. # Typedef
  79. snippet td
  80. typedef ${1:int} ${2:MyCustomType};${3}
  81. # Struct
  82. snippet st
  83. struct ${1:`Filename('$1_t', 'name')`} {
  84. ${2:/* data */}
  85. }${3: /* optional variable list */};${4}
  86. # Typedef struct
  87. snippet tds
  88. typedef struct ${2:_$1 }{
  89. ${3:/* data */}
  90. } ${1:`Filename('$1_t', 'name')`};
  91. # Typdef enum
  92. snippet tde
  93. typedef enum {
  94. ${1:/* data */}
  95. } ${2:foo};
  96. # printf
  97. # unfortunately version this isn't as nice as TextMates's, given the lack of a
  98. # dynamic `...`
  99. snippet pr
  100. printf("${1:%s}\n"${2});${3}
  101. # fprintf (again, this isn't as nice as TextMate's version, but it works)
  102. snippet fpr
  103. fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
  104. snippet .
  105. [${1}]${2}
  106. snippet un
  107. unsigned