├── .editorconfig ├── README.md └── UltiSnips └── javascript.snippets /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 2 6 | end_of_line = lf 7 | max_line_length = 100 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vim ES2015 Snippets 2 | 3 | A Vim snippet library for ES2015. You may also want to check out [vim-react-snippets](https://github.com/epilande/vim-react-snippets). 4 | 5 | Requires [UltiSnips](https://github.com/SirVer/ultisnips). 6 | 7 | ![vim-es2015-snippets](http://i.imgur.com/7EnLr1m.gif) 8 | 9 | ## Installation 10 | 11 | Using vim-plug: 12 | 13 | ```vim 14 | " ES2015 code snippets 15 | Plug 'epilande/vim-es2015-snippets' 16 | 17 | " React code snippets (Optional) 18 | Plug 'epilande/vim-react-snippets' 19 | 20 | " Ultisnips 21 | Plug 'SirVer/ultisnips' 22 | 23 | " Trigger configuration (Optional) 24 | " let g:UltiSnipsExpandTrigger="" 25 | ``` 26 | 27 | ## Usage 28 | In a JavaScript or JSX file, type a trigger name while in Insert mode, then press Ultisnips trigger key. In my case I have it mapped to ``. 29 | 30 | In Insert mode 31 | 32 | ```javascript 33 | c=> 34 | ``` 35 | 36 | Will expand to 37 | 38 | ```javascript 39 | const name = (args) => { 40 | return ; 41 | }; 42 | ``` 43 | 44 | Check out [`UltiSnips/javascript.snippets`](UltiSnips/javascript.snippets) to see all snippets. 45 | 46 | -------------------------------------------------------------------------------- /UltiSnips/javascript.snippets: -------------------------------------------------------------------------------- 1 | # ES2015 2 | snippet "c(onst)?" "const" br 3 | const ${1} = ${2:'$1'}; 4 | endsnippet 5 | 6 | snippet "l(et)?" "let" br 7 | let ${1} = ${2:'$1'}; 8 | endsnippet 9 | 10 | snippet "i(mport|mp|m)?" "import" br 11 | import ${1} from '${2:./}${3:$1}'; 12 | endsnippet 13 | 14 | snippet "e(xport|xp|x)?" "export" br 15 | export ${1:default }; 16 | endsnippet 17 | 18 | snippet ie "Import file then export" b 19 | import ${1} from '${2:./}${3:$1}'; 20 | 21 | export ${4:default} $1; 22 | endsnippet 23 | 24 | snippet r "return" 25 | return ${0:result;} 26 | endsnippet 27 | 28 | snippet : "Object Value JS" 29 | ${1:key}: ${0:value}, 30 | endsnippet 31 | 32 | snippet :f "method: func(...) { ... }" 33 | ${1:key}: ${2:(args)} => { 34 | return $4; 35 | }${3:,} 36 | endsnippet 37 | 38 | snippet "\.(map|filter|forEach|reduce)" "Array method with an arrow function" r 39 | .`!p snip.rv = match.group(1)`(${1:(c, i)} => { 40 | return $2; 41 | }); 42 | endsnippet 43 | 44 | snippet "\.(map|filter|forEach|reduce)=" "Array method with an arrow function inline" rA 45 | .`!p snip.rv = match.group(1)`(${1:(c, i)} => $2); 46 | endsnippet 47 | 48 | snippet => "Arrow function" 49 | (${1:args}) => { 50 | return $3; 51 | }${2:;} 52 | endsnippet 53 | 54 | snippet =>> "Inline arrow function" A 55 | (${1:args}) => ($2); 56 | endsnippet 57 | 58 | snippet c=> "Const Function" bA 59 | const ${1:name} = (${2:args}) => { 60 | return $4; 61 | }${3:;} 62 | endsnippet 63 | 64 | snippet expf "Export function" b 65 | export ${1:default }function ${2:name}($3) { 66 | $4 67 | }; 68 | endsnippet 69 | 70 | snippet fun* "Generator" 71 | function* ${1:name}($2) { 72 | yield $3; 73 | } 74 | endsnippet 75 | 76 | snippet forof "For of loop" b 77 | for (let ${1:value} of ${2:iterable}) { 78 | ${3:$1} 79 | } 80 | endsnippet 81 | 82 | snippet class "Class" 83 | class ${1:Name} { 84 | constructor(${2:arg}) { 85 | $3 86 | } 87 | $4 88 | } 89 | endsnippet 90 | 91 | snippet cl "console.log(...)" 92 | console.log('${2:$1: }', ${1}); 93 | endsnippet 94 | --------------------------------------------------------------------------------