forked from vim-scripts/snipMate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some other bugs for compatibility with supertab.vim and 'set expandtab' and added check to ensure snippets are not loaded twice. I also changed the "Snip" command to "Snipp" to maintain compatibility with vimscript #244 (imaps.vim). Unfortunately this breaks backward compatibility; to update any snippets you have added, just execute this regex on the appropriate files: ":%s/exe \(.\)Snip /exe \1Snipp /g"
- Loading branch information
1 parent
02da7de
commit d733b01
Showing
14 changed files
with
414 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
if !exists('g:loaded_snips') | ||
if !exists('g:loaded_snips') || exists('s:did_snips') | ||
fini | ||
en | ||
let s:did_snips = 1 | ||
|
||
" main() | ||
exe "Snip main int main (int argc, char const* argv[])\n{\n\t${1}\n\treturn 0;\n}" | ||
exe "Snipp main int main (int argc, char const* argv[])\n{\n\t${1}\n\treturn 0;\n}" | ||
" #include <...> | ||
exe 'Snip inc #include <${1:stdio}.h>${2}' | ||
exe 'Snipp inc #include <${1:stdio}.h>${2}' | ||
" #include "..." | ||
exe 'Snip Inc #include "${1:`Filename("$1.h")`}"${2}' | ||
exe 'Snipp Inc #include "${1:`Filename("$1.h")`}"${2}' | ||
" #ifndef ... #define ... #endif | ||
exe "Snip def #ifndef $1\n#define ${1:SYMBOL} ${2:value}\n#endif${3}" | ||
exe "Snipp def #ifndef $1\n#define ${1:SYMBOL} ${2:value}\n#endif${3}" | ||
" Header Include-Guard | ||
" (the randomizer code is taken directly from TextMate; I don't know how to do | ||
" it in vim script, it could probably be cleaner) | ||
exe "Snip once #ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system(\"/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'\"))`}\n" | ||
exe "Snipp once #ifndef ${1:`toupper(Filename('', 'UNTITLED').'_'.system(\"/usr/bin/ruby -e 'print (rand * 2821109907455).round.to_s(36)'\"))`}\n" | ||
\ ."#define $1\n\n${2}\n\n#endif /* end of include guard: $1 */" | ||
" Read File Into Vector | ||
exe "Snip readfile std::vector<char> v;\nif (FILE *${2:fp} = fopen(${1:\"filename\"}, \"r\")) {\n\tchar buf[1024];\n\twhile (size_t len = " | ||
exe "Snipp readfile std::vector<char> v;\nif (FILE *${2:fp} = fopen(${1:\"filename\"}, \"r\")) {\n\tchar buf[1024];\n\twhile (size_t len = " | ||
\ ."fread(buf, 1, sizeof(buf), $2))\n\t\tv.insert(v.end(), buf, buf + len);\n\tfclose($2);\n}${3}" | ||
" If Condition | ||
exe "Snip if if (${1:/* condition */}) {\n\t${2:/* code */}\n}" | ||
exe "Snip el else {\n\t${1}\n}" | ||
exe "Snipp if if (${1:/* condition */}) {\n\t${2:/* code */}\n}" | ||
exe "Snipp el else {\n\t${1}\n}" | ||
" Tertiary conditional | ||
exe 'Snip t ${1:/* condition */} ? ${2:a} : ${3:b}' | ||
exe 'Snipp t ${1:/* condition */} ? ${2:a} : ${3:b}' | ||
" Do While Loop | ||
exe "Snip do do {\n\t${2:/* code */}\n} while (${1:/* condition */});" | ||
exe "Snipp do do {\n\t${2:/* code */}\n} while (${1:/* condition */});" | ||
" While Loop | ||
exe "Snip wh while (${1:/* condition */}) {\n\t${2:/* code */}\n}" | ||
exe "Snipp wh while (${1:/* condition */}) {\n\t${2:/* code */}\n}" | ||
" For Loop | ||
exe "Snip for for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {\n\t${4:/* code */}\n}" | ||
exe "Snipp for for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {\n\t${4:/* code */}\n}" | ||
" Custom For Loop | ||
exe "Snip forr for (${1:i} = 0; ${2:$1 < 5}; $1${3:++}) {\n\t${4:/* code */}\n}" | ||
exe "Snipp forr for (${1:i} = 0; ${2:$1 < 5}; $1${3:++}) {\n\t${4:/* code */}\n}" | ||
" Function | ||
exe "Snip fun ${1:void} ${2:function_name} (${3})\n{\n\t${4:/* code */}\n}" | ||
exe "Snipp fun ${1:void} ${2:function_name} (${3})\n{\n\t${4:/* code */}\n}" | ||
" Typedef | ||
exe 'Snip td typedef ${1:int} ${2:MyCustomType};' | ||
exe 'Snipp td typedef ${1:int} ${2:MyCustomType};' | ||
" Struct | ||
exe "Snip st struct ${1:`Filename('$1_t', 'name')`} {\n\t${2:/* data */}\n}${3: /* optional variable list */};${4}" | ||
exe "Snipp st struct ${1:`Filename('$1_t', 'name')`} {\n\t${2:/* data */}\n}${3: /* optional variable list */};${4}" | ||
" Typedef struct | ||
exe "Snip tds typedef struct {\n\t${2:/* data */}\n} ${1:`Filename('$1_t', 'name')`};" | ||
exe "Snipp tds typedef struct {\n\t${2:/* data */}\n} ${1:`Filename('$1_t', 'name')`};" | ||
" Class | ||
exe "Snip cl class ${1:`Filename('$1_t', 'name')`} {\npublic:\n\t$1 (${2:arguments});\n\tvirtual ~$1 ();\n\nprivate:\n\t${3:/* data */}\n};" | ||
exe "Snipp cl class ${1:`Filename('$1_t', 'name')`} {\npublic:\n\t$1 (${2:arguments});\n\tvirtual ~$1 ();\n\nprivate:\n\t${3:/* data */}\n};" | ||
" Namespace | ||
exe "Snip ns namespace ${1:`Filename('', 'my')`} {\n\t${2}\n} /* $1 */" | ||
exe "Snipp ns namespace ${1:`Filename('', 'my')`} {\n\t${2}\n} /* $1 */" | ||
" std::map | ||
exe "Snip map std::map<${1:key}, ${2:value}> map${3};" | ||
exe "Snipp map std::map<${1:key}, ${2:value}> map${3};" | ||
" std::vector | ||
exe "Snip vector std::vector<${1:char}> v${2};" | ||
exe "Snipp vector std::vector<${1:char}> v${2};" | ||
" printf | ||
" unfortunately version this isn't as nice as TextMates's, given the lack of a | ||
" dynamic `...` | ||
exe 'Snip pr printf("${1:%s}\n"${2});${3}' | ||
exe 'Snipp pr printf("${1:%s}\n"${2});${3}' | ||
" fprintf (again, this isn't as nice as TextMate's version, but it works) | ||
exe 'Snip fpr fprintf(${1:stderr}, "${2:%s}\n"${3});${4}' | ||
exe 'Snipp fpr fprintf(${1:stderr}, "${2:%s}\n"${3});${4}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
if !exists('loaded_snips') | ||
if !exists('loaded_snips') || exists('s:did_snips') | ||
fini | ||
en | ||
let s:did_snips = 1 | ||
|
||
exe "Snip main public static void main (String [] args)\n{\n\t${1:/* code */}\n}" | ||
exe 'Snip pu public' | ||
exe 'Snip po protected' | ||
exe 'Snip pr private' | ||
exe 'Snip st static' | ||
exe 'Snip fi final' | ||
exe 'Snip ab abstract' | ||
exe 'Snip re return' | ||
exe 'Snip br break;' | ||
exe "Snip de default:\n\t${1}" | ||
exe 'Snip ca catch(${1:Exception} ${2:e}) ${3}' | ||
exe 'Snip th throw ' | ||
exe 'Snip sy synchronized' | ||
exe 'Snip im import' | ||
exe 'Snip j.u java.util' | ||
exe 'Snip j.i java.io.' | ||
exe 'Snip j.b java.beans.' | ||
exe 'Snip j.n java.net.' | ||
exe 'Snip j.m java.math.' | ||
exe 'Snip if if (${1}) ${2}' | ||
exe 'Snip el else ' | ||
exe 'Snip elif else if (${1}) ${2}' | ||
exe 'Snip wh while (${1}) ${2}' | ||
exe 'Snip for for (${1}; ${2}; ${3}) ${4}' | ||
exe 'Snip fore for (${1} : ${2}) ${3}' | ||
exe 'Snip sw switch (${1}) ${2}' | ||
exe "Snip cs case ${1}:\n\t${2}\n${3}" | ||
exe 'Snip tc public class ${1:`Filename()`} extends ${2:TestCase}' | ||
exe 'Snip t public void test${1:Name}() throws Exception ${2}' | ||
exe 'Snip cl class ${1:`Filename("", "untitled")`} ${2}' | ||
exe 'Snip in interface ${1:`Filename("", "untitled")`} ${2:extends Parent}${3}' | ||
exe 'Snip m ${1:void} ${2:method}(${3}) ${4:throws }${5}' | ||
exe 'Snip v ${1:String} ${2:var}${3: = null}${4};${5}' | ||
exe 'Snip co static public final ${1:String} ${2:var} = ${3};${4}' | ||
exe 'Snip cos static public final String ${1:var} = "${2}";${3}' | ||
exe 'Snip as assert ${1:test} : "${2:Failure message}";${3}' | ||
exe "Snipp main public static void main (String [] args)\n{\n\t${1:/* code */}\n}" | ||
exe 'Snipp pu public' | ||
exe 'Snipp po protected' | ||
exe 'Snipp pr private' | ||
exe 'Snipp st static' | ||
exe 'Snipp fi final' | ||
exe 'Snipp ab abstract' | ||
exe 'Snipp re return' | ||
exe 'Snipp br break;' | ||
exe "Snipp de default:\n\t${1}" | ||
exe 'Snipp ca catch(${1:Exception} ${2:e}) ${3}' | ||
exe 'Snipp th throw ' | ||
exe 'Snipp sy synchronized' | ||
exe 'Snipp im import' | ||
exe 'Snipp j.u java.util' | ||
exe 'Snipp j.i java.io.' | ||
exe 'Snipp j.b java.beans.' | ||
exe 'Snipp j.n java.net.' | ||
exe 'Snipp j.m java.math.' | ||
exe 'Snipp if if (${1}) ${2}' | ||
exe 'Snipp el else ' | ||
exe 'Snipp elif else if (${1}) ${2}' | ||
exe 'Snipp wh while (${1}) ${2}' | ||
exe 'Snipp for for (${1}; ${2}; ${3}) ${4}' | ||
exe 'Snipp fore for (${1} : ${2}) ${3}' | ||
exe 'Snipp sw switch (${1}) ${2}' | ||
exe "Snipp cs case ${1}:\n\t${2}\n${3}" | ||
exe 'Snipp tc public class ${1:`Filename()`} extends ${2:TestCase}' | ||
exe 'Snipp t public void test${1:Name}() throws Exception ${2}' | ||
exe 'Snipp cl class ${1:`Filename("", "untitled")`} ${2}' | ||
exe 'Snipp in interface ${1:`Filename("", "untitled")`} ${2:extends Parent}${3}' | ||
exe 'Snipp m ${1:void} ${2:method}(${3}) ${4:throws }${5}' | ||
exe 'Snipp v ${1:String} ${2:var}${3: = null}${4};${5}' | ||
exe 'Snipp co static public final ${1:String} ${2:var} = ${3};${4}' | ||
exe 'Snipp cos static public final String ${1:var} = "${2}";${3}' | ||
exe 'Snipp as assert ${1:test} : "${2:Failure message}";${3}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
if !exists('loaded_snips') | ||
if !exists('loaded_snips') || exists('s:did_snips') | ||
fini | ||
en | ||
let s:did_snips = 1 | ||
|
||
" Prototype | ||
exe "Snip proto ${1:class_name}.prototype.${2:method_name} =\nfunction(${3:first_argument}) {\n\t${4:// body...}\n};" | ||
exe "Snipp proto ${1:class_name}.prototype.${2:method_name} =\nfunction(${3:first_argument}) {\n\t${4:// body...}\n};" | ||
" Function | ||
exe "Snip fun function ${1:function_name} (${2:argument}) {\n\t${3:// body...}\n}" | ||
exe "Snipp fun function ${1:function_name} (${2:argument}) {\n\t${3:// body...}\n}" | ||
" Anonymous Function | ||
exe 'Snip f function(${1}) {${2}};' | ||
exe 'Snipp f function(${1}) {${2}};' | ||
" if | ||
exe 'Snip if if (${1:true}) {${2}};' | ||
exe 'Snipp if if (${1:true}) {${2}};' | ||
" if ... else | ||
exe "Snip ife if (${1:true}) {${2}}\nelse{${3}};" | ||
exe "Snipp ife if (${1:true}) {${2}}\nelse{${3}};" | ||
" tertiary conditional | ||
exe 'Snip t ${1:/* condition */} ? ${2:a} : ${3:b}' | ||
exe 'Snipp t ${1:/* condition */} ? ${2:a} : ${3:b}' | ||
" switch | ||
exe "Snip switch switch(${1:expression}) {\n\tcase '${3:case}':\n\t\t${4:// code}\n\t\tbreak;\n\t${5}\n\tdefault:\n\t\t${2:// code}\n}" | ||
exe "Snipp switch switch(${1:expression}) {\n\tcase '${3:case}':\n\t\t${4:// code}\n\t\tbreak;\n\t${5}\n\tdefault:\n\t\t${2:// code}\n}" | ||
" case | ||
exe "Snip case case '${1:case}':\n\t${2:// code}\n\tbreak;\n${3}" | ||
exe "Snipp case case '${1:case}':\n\t${2:// code}\n\tbreak;\n${3}" | ||
" for (...) {...} | ||
exe "Snip for for (var ${2:i} = 0; $2 < ${1:Things}.length; $2${3:++}) {\n\t${4:$1[$2]}\n};" | ||
exe "Snipp for for (var ${2:i} = 0; $2 < ${1:Things}.length; $2${3:++}) {\n\t${4:$1[$2]}\n};" | ||
" for (...) {...} (Improved Native For-Loop) | ||
exe "Snip forr for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2${3:--}) {\n\t${4:$1[$2]}\n};" | ||
exe "Snipp forr for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2${3:--}) {\n\t${4:$1[$2]}\n};" | ||
" while (...) {...} | ||
exe "Snip wh while (${1:/* condition */}) {\n\t${2:/* code */}\n}" | ||
exe "Snipp wh while (${1:/* condition */}) {\n\t${2:/* code */}\n}" | ||
" do...while | ||
exe "Snip do do {\n\t${2:/* code */}\n} while (${1:/* condition */});" | ||
exe "Snipp do do {\n\t${2:/* code */}\n} while (${1:/* condition */});" | ||
" Object Method | ||
exe "Snip :f ${1:method_name}: function(${2:attribute}) {\n\t${4}\n}${3:,}" | ||
exe "Snipp :f ${1:method_name}: function(${2:attribute}) {\n\t${4}\n}${3:,}" | ||
" setTimeout function | ||
exe 'Snip timeout setTimeout(function() {${3}}${2}, ${1:10};' | ||
exe 'Snipp timeout setTimeout(function() {${3}}${2}, ${1:10};' | ||
" Get Elements | ||
exe "Snip get getElementsBy${1:TagName}('${2}')${3}" | ||
exe "Snipp get getElementsBy${1:TagName}('${2}')${3}" | ||
" Get Element | ||
exe "Snip gett getElementBy${1:Id}('${2}')${3}" | ||
exe "Snipp gett getElementBy${1:Id}('${2}')${3}" |
Oops, something went wrong.