Merge pull request #132 from abroder/master
Reworked C/CPP snippets files - reorganized and more feature-complete.
This commit is contained in:
commit
a7b8c5365c
@ -1,38 +1,45 @@
|
||||
# main()
|
||||
## Main
|
||||
# main
|
||||
snippet main
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
${1}
|
||||
return 0;
|
||||
}
|
||||
# main(void)
|
||||
snippet mainn
|
||||
int main(void)
|
||||
{
|
||||
${1}
|
||||
return 0;
|
||||
}
|
||||
##
|
||||
## Preprocessor
|
||||
# #include <...>
|
||||
snippet inc
|
||||
#include <${1:stdio}.h>${2}
|
||||
# #include "..."
|
||||
snippet Inc
|
||||
#include "${1:`Filename("$1.h")`}"${2}
|
||||
# #ifndef ... #define ... #endif
|
||||
snippet Def
|
||||
# ifndef...define...endif
|
||||
snippet ndef
|
||||
#ifndef $1
|
||||
#define ${1:SYMBOL} ${2:value}
|
||||
#endif${3}
|
||||
# define
|
||||
snippet def
|
||||
#define
|
||||
# ifdef...endif
|
||||
snippet ifdef
|
||||
#ifdef ${1:FOO}
|
||||
${2:#define }
|
||||
#endif
|
||||
#endif${3}
|
||||
# if
|
||||
snippet #if
|
||||
#if ${1:FOO}
|
||||
${2}
|
||||
#endif
|
||||
# Header Include-Guard
|
||||
# header include guard
|
||||
snippet once
|
||||
#ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
|
||||
|
||||
@ -41,73 +48,89 @@ snippet once
|
||||
${2}
|
||||
|
||||
#endif /* end of include guard: $1 */
|
||||
# If Condition
|
||||
##
|
||||
## Control Statements
|
||||
# if
|
||||
snippet if
|
||||
if (${1:/* condition */}) {
|
||||
${2:/* code */}
|
||||
}
|
||||
}${3}
|
||||
# else
|
||||
snippet el
|
||||
else {
|
||||
${1}
|
||||
}
|
||||
# Ternary conditional
|
||||
}${3}
|
||||
# else if
|
||||
snippet elif
|
||||
else if (${1:/* condition */}) {
|
||||
${2:/* code */}
|
||||
}${3}
|
||||
# ternary
|
||||
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
|
||||
##
|
||||
## Loops
|
||||
# for
|
||||
snippet for
|
||||
for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
||||
${4:/* code */}
|
||||
}
|
||||
# Custom For Loop
|
||||
}${5}
|
||||
# for (custom)
|
||||
snippet forr
|
||||
for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
|
||||
${5:/* code */}
|
||||
}
|
||||
# Function
|
||||
}${6}
|
||||
# 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 */}
|
||||
}
|
||||
# Function Declaration
|
||||
}${5}
|
||||
# function declaration
|
||||
snippet fund
|
||||
${1:void} ${2:function_name}(${3});${4}
|
||||
# Typedef
|
||||
##
|
||||
## Types
|
||||
# typedef
|
||||
snippet td
|
||||
typedef ${1:int} ${2:MyCustomType};${3}
|
||||
# Struct
|
||||
# struct
|
||||
snippet st
|
||||
struct ${1:`Filename('$1_t', 'name')`} {
|
||||
${2:/* data */}
|
||||
}${3: /* optional variable list */};${4}
|
||||
# Typedef struct
|
||||
# typedef struct
|
||||
snippet tds
|
||||
typedef struct ${2:_$1 }{
|
||||
${3:/* data */}
|
||||
} ${1:`Filename('$1_t', 'name')`};
|
||||
# Typdef enum
|
||||
} ${1:`Filename('$1_t', 'name')`};${4}
|
||||
# typedef enum
|
||||
snippet tde
|
||||
typedef enum {
|
||||
${1:/* data */}
|
||||
} ${2:foo};
|
||||
} ${2:foo};${3}
|
||||
##
|
||||
## Input/Output
|
||||
# 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}
|
||||
##
|
||||
## Miscellaneous
|
||||
# This is kind of convenient
|
||||
snippet .
|
||||
[${1}]${2}
|
||||
|
@ -1,18 +1,73 @@
|
||||
## STL Collections
|
||||
# std::array
|
||||
snippet array
|
||||
std::array<${1:T}, ${2:N}> ${3};${4}
|
||||
# std::vector
|
||||
snippet vector
|
||||
std::vector<${1:char}> ${2};
|
||||
std::vector<${1:T}> ${2};${3}
|
||||
# std::deque
|
||||
snippet deque
|
||||
std::deque<${1:T}> ${2};${3}
|
||||
# std::forward_list
|
||||
snippet flist
|
||||
std::forward_list<${1:T}> ${2};${3}
|
||||
# std::list
|
||||
snippet list
|
||||
std::list<${1:T}> ${2};${3}
|
||||
# std::set
|
||||
snippet set
|
||||
std::set<${1:T}> ${2};${3}
|
||||
# std::map
|
||||
snippet map
|
||||
std::map<${1:key}, ${2:value}> ${3};
|
||||
|
||||
# std::cout
|
||||
snippet cout
|
||||
std::cout << ${1} << std::endl;
|
||||
# std::cin
|
||||
snippet cin
|
||||
std::cin >> ${1};
|
||||
std::map<${1:Key}, ${2:T}> ${3};${4}
|
||||
# std::multiset
|
||||
snippet mset
|
||||
std::multiset<${1:T}> ${2};${3}
|
||||
# std::multimap
|
||||
snippet mmap
|
||||
std::multimap<${1:Key}, ${2:T}> ${3};${4}
|
||||
# std::unordered_set
|
||||
snippet uset
|
||||
std::unordered_set<${1:T}> ${2};${3}
|
||||
# std::unordered_map
|
||||
snippet umap
|
||||
std::unordered_map<${1:Key}, ${2:T}> ${3};${4}
|
||||
# std::unordered_multiset
|
||||
snippet umset
|
||||
std::unordered_multiset<${1:T}> ${2};${3}
|
||||
# std::unordered_multimap
|
||||
snippet ummap
|
||||
std::unordered_multimap<${1:Key}, ${2:T}> ${3};${4}
|
||||
# std::stack
|
||||
snippet stack
|
||||
std::stack<${1:T}> ${2};${3}
|
||||
# std::queue
|
||||
snippet queue
|
||||
std::queue<${1:T}> ${2};${3}
|
||||
# std::priority_queue
|
||||
snippet pqueue
|
||||
std::priority_queue<${1:T}> ${2};${3}
|
||||
##
|
||||
## Access Modifiers
|
||||
# private
|
||||
snippet pri
|
||||
private
|
||||
# protected
|
||||
snippet pro
|
||||
protected
|
||||
# public
|
||||
snippet pub
|
||||
public
|
||||
# friend
|
||||
snippet fr
|
||||
friend
|
||||
# mutable
|
||||
snippet mu
|
||||
mutable
|
||||
##
|
||||
## Class
|
||||
# class
|
||||
snippet class
|
||||
snippet cl
|
||||
class ${1:`Filename('$1', 'name')`}
|
||||
{
|
||||
public:
|
||||
@ -22,48 +77,55 @@ snippet class
|
||||
private:
|
||||
${3:/* data */}
|
||||
};
|
||||
|
||||
# member function implementations
|
||||
# member function implementation
|
||||
snippet mfun
|
||||
${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
|
||||
${5:return};
|
||||
${5:/* code */}
|
||||
}
|
||||
# namespace
|
||||
snippet ns
|
||||
namespace ${1:`Filename('', 'my')`} {
|
||||
${2}
|
||||
} /* namespace $1 */
|
||||
|
||||
# for i loop
|
||||
##
|
||||
## Input/Output
|
||||
# std::cout
|
||||
snippet cout
|
||||
std::cout << ${1} << std::endl;${2}
|
||||
# std::cin
|
||||
snippet cin
|
||||
std::cin >> ${1};${2}
|
||||
##
|
||||
## Iteration
|
||||
# for i
|
||||
snippet fori
|
||||
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
||||
${4:/* code */}
|
||||
}
|
||||
}${5}
|
||||
|
||||
# foreach
|
||||
snippet fore
|
||||
for (${1:auto} ${2:i} : ${3:container}) {
|
||||
${4:/* code */}
|
||||
}
|
||||
}${5}
|
||||
# iterator
|
||||
snippet iter
|
||||
for (${1:std::vector}<${2:type}>::${3:const_iterator} ${4:i} = ${5:container}.begin(); $4 != $5.end(); ++$4) {
|
||||
${6}
|
||||
}
|
||||
}${7}
|
||||
|
||||
# auto iterator
|
||||
snippet itera
|
||||
for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) {
|
||||
${2:std::cout << *$1 << std::endl;}
|
||||
}
|
||||
|
||||
# read file into vector
|
||||
snippet readfile
|
||||
std::vector<char> v;
|
||||
if (FILE *${2:fp} = fopen(${1:"filename"}, "r")) {
|
||||
char buf[1024];
|
||||
while (size_t len = fread(buf, 1, sizeof(buf), $2))
|
||||
v.insert(v.end(), buf, buf + len);
|
||||
fclose($2);
|
||||
}${3}
|
||||
|
||||
##
|
||||
## Lambdas
|
||||
# lamda (one line)
|
||||
snippet ld
|
||||
[${1}](${2}){${3:/* code */}}${4}
|
||||
# lambda (multi-line)
|
||||
snippet lld
|
||||
[${1}](${2}){
|
||||
${3:/* code */}
|
||||
}${4}
|
||||
|
Loading…
Reference in New Issue
Block a user