1
0
Fork 0
mirror of synced 2024-11-29 20:25:34 -05:00
ultimate-vim/sources_non_forked/vim-snippets/UltiSnips/javascript.snippets

226 lines
5.9 KiB
Text
Raw Normal View History

priority -50
2017-03-07 12:04:28 -05:00
############
# COMMON #
############
# The smart snippets use a global options called
# "g:ultisnips_javascript.{option}" which can control the format
# of trailing semicolon, space before function paren, etc.
2017-09-02 06:43:18 -04:00
#
# e.g.
# let g:ultisnips_javascript = {
# \ 'keyword-spacing': 'always',
# \ 'semi': 'never',
# \ 'space-before-function-paren': 'always',
# \ }
2017-03-07 12:04:28 -05:00
global !p
from javascript_snippets import (
semi, space_before_function_paren, keyword_spacing
)
endglobal
2012-08-16 23:41:25 -04:00
###########################################################################
# TextMate Snippets #
###########################################################################
snippet get "Get Elements"
2018-06-14 06:31:12 -04:00
getElement${1/(T)|(C)|.*/(?1:s)(?2:s)/}By${1:T}${1/(T)|(I)|(C).*/(?1:agName)(?2:d)(?3:lassName)/}('$2')
2012-08-16 23:41:25 -04:00
endsnippet
snippet '':f "object method string"
2017-03-07 12:04:28 -05:00
'${1:${2:#thing}:${3:click}}': function`!p snip.rv = space_before_function_paren(snip)`(element) {
${VISUAL}$0
2012-08-16 23:41:25 -04:00
}${10:,}
endsnippet
snippet :f "Object Method"
2017-03-07 12:04:28 -05:00
${1:method_name}: function`!p snip.rv = space_before_function_paren(snip)`(${3:attribute}) {
${VISUAL}$0
2012-08-16 23:41:25 -04:00
}${10:,}
endsnippet
snippet :, "Object Value JS"
${1:value_name}: ${0:value},
2012-08-16 23:41:25 -04:00
endsnippet
snippet : "Object key key: 'value'"
${1:key}: ${2:"${3:value}"}${4:, }
endsnippet
snippet proto "Prototype (proto)"
2017-03-07 12:04:28 -05:00
${1:class_name}.prototype.${2:method_name} = function`!p snip.rv = space_before_function_paren(snip)`(${3:first_argument}) {
${VISUAL}$0
2017-03-07 12:04:28 -05:00
}`!p snip.rv = semi(snip)`
2012-08-16 23:41:25 -04:00
endsnippet
2019-01-08 05:11:54 -05:00
snippet fun "function (named)" b
2017-03-07 12:04:28 -05:00
function ${1:function_name}`!p snip.rv = space_before_function_paren(snip)`(${2:argument}) {
${VISUAL}$0
2012-08-16 23:41:25 -04:00
}
endsnippet
2019-01-08 05:11:54 -05:00
snippet vf "function (assigned to var)"
2017-03-07 12:04:28 -05:00
${1:var }${2:function_name} = function $2`!p snip.rv = space_before_function_paren(snip)`($3) {
${VISUAL}$0
2017-03-07 12:04:28 -05:00
}`!p snip.rv = semi(snip)`
2016-03-14 06:04:57 -04:00
endsnippet
2019-01-08 05:11:54 -05:00
# Drop priority so this only triggers when not beginning of line.
priority -51
snippet fun "function (anonymous)" w
function`!p snip.rv = space_before_function_paren(snip)`($1) {
${VISUAL}$0
}$2
endsnippet
priority -50
snippet anf "function (anonymous)" i
2017-03-07 12:04:28 -05:00
function`!p snip.rv = space_before_function_paren(snip)`($1) {
2016-03-14 06:04:57 -04:00
${VISUAL}$0
}
2012-08-16 23:41:25 -04:00
endsnippet
2015-01-18 07:58:28 -05:00
snippet iife "Immediately-Invoked Function Expression (iife)"
2017-03-07 12:04:28 -05:00
(function`!p snip.rv = space_before_function_paren(snip)`(${1:window}) {
${VISUAL}$0
2017-03-07 12:04:28 -05:00
}(${2:$1}))`!p snip.rv = semi(snip)`
endsnippet
snippet ;fe "Minify safe iife"
;(function`!p snip.rv = space_before_function_paren(snip)`(${1}) {
${VISUAL}$0
}(${2}))
2012-08-16 23:41:25 -04:00
endsnippet
snippet timeout "setTimeout function"
2017-03-07 12:04:28 -05:00
setTimeout(function`!p snip.rv = space_before_function_paren(snip)`() {
${VISUAL}$0
2017-03-07 12:04:28 -05:00
}${2:.bind(${3:this})}, ${1:10})`!p snip.rv = semi(snip)`
endsnippet
2014-07-02 07:18:18 -04:00
snippet fi "for prop in obj using hasOwnProperty" b
2017-03-07 12:04:28 -05:00
for`!p snip.rv = keyword_spacing(snip)`(${1:prop} in ${2:obj}){
if`!p snip.rv = keyword_spacing(snip)`($2.hasOwnProperty($1)) {
2014-07-02 07:18:18 -04:00
${VISUAL}$0
}
}
endsnippet
2017-03-07 12:04:28 -05:00
snippet if "if (condition) { ... }"
if`!p snip.rv = keyword_spacing(snip)`(${1:true}) {
${VISUAL}$0
}
endsnippet
snippet ife "if (condition) { ... } else { ... }"
if`!p snip.rv = keyword_spacing(snip)`(${1:true}) {
${VISUAL}$0
}`!p snip.rv = keyword_spacing(snip)`else`!p snip.rv = keyword_spacing(snip)`{
${2}
}
endsnippet
snippet switch
switch`!p snip.rv = keyword_spacing(snip)`(${VISUAL}${1:expression}) {
case '${VISUAL}${3:case}':
${4}
break`!p snip.rv = semi(snip)`
${0}
default:
${2}
}
endsnippet
snippet case "case 'xyz': ... break"
case`!p snip.rv = keyword_spacing(snip)`'${VISUAL}${1:case}':
${VISUAL}$0
break`!p snip.rv = semi(snip)`
endsnippet
snippet do "do { ... } while (condition)"
do`!p snip.rv = keyword_spacing(snip)`{
${VISUAL}$0
}`!p snip.rv = keyword_spacing(snip)`while`!p snip.rv = keyword_spacing(snip)`(${1:/* condition */})`!p snip.rv = semi(snip)`
endsnippet
snippet ret "Return statement"
return ${VISUAL}$0`!p snip.rv = semi(snip)`
endsnippet
snippet us
'use strict'`!p snip.rv = semi(snip)`
endsnippet
2021-07-04 16:47:44 -04:00
snippet imp "import"
import ${2} from ${1}
endsnippet
2021-10-11 05:30:43 -04:00
# Debugging
snippet de
debugger`!p snip.rv = semi(snip)`
endsnippet
snippet cl "console.log"
console.log(${0})`!p snip.rv = semi(snip)`
endsnippet
snippet cd "console.debug"
console.debug(${0})`!p snip.rv = semi(snip)`
endsnippet
snippet ce "console.error"
console.error(${0})`!p snip.rv = semi(snip)`
endsnippet
snippet cw "console.warn"
console.warn(${0})`!p snip.rv = semi(snip)`
endsnippet
snippet ci "console.info"
console.info(${0})`!p snip.rv = semi(snip)`
endsnippet
snippet ct "console.trace"
console.trace(${0:label})`!p snip.rv = semi(snip)`
endsnippet
snippet ctime "console.time ... console.timeEnd"
console.time("${1:label}")`!p snip.rv = semi(snip)`
${0:${VISUAL}}
console.timeEnd("$1")`!p snip.rv = semi(snip)`
endsnippet
snippet ctimestamp "console.timeStamp"
console.timeStamp("${1:label}")`!p snip.rv = semi(snip)`
endsnippet
snippet ca "console.assert"
console.assert(${1:expression}, ${0:obj})`!p snip.rv = semi(snip)`
endsnippet
snippet cclear "console.clear"
console.clear()`!p snip.rv = semi(snip)`
endsnippet
snippet cdir "console.dir"
console.dir(${0:obj})`!p snip.rv = semi(snip)`
endsnippet
snippet cdirx "console.dirxml"
console.dirxml(${1:object})`!p snip.rv = semi(snip)`
endsnippet
snippet cgroup "console.group"
console.group("${1:label}")`!p snip.rv = semi(snip)`
${0:${VISUAL}}
console.groupEnd()`!p snip.rv = semi(snip)`
endsnippet
snippet cgroupc "console.groupCollapsed"
console.groupCollapsed("${1:label}")`!p snip.rv = semi(snip)`
${0:${VISUAL}}
console.groupEnd()`!p snip.rv = semi(snip)`
endsnippet
snippet cprof "console.profile"
console.profile("${1:label}")`!p snip.rv = semi(snip)`
${0:${VISUAL}}
console.profileEnd()`!p snip.rv = semi(snip)`
endsnippet
snippet ctable "console.table"
console.table(${1:"${2:value}"})`!p snip.rv = semi(snip)`
endsnippet
snippet clstr "console.log stringified"
console.log(JSON.stringify(${0}, null, 2))`!p snip.rv = semi(snip)`
endsnippet
2012-08-16 23:41:25 -04:00
# vim:ft=snippets: