-
Notifications
You must be signed in to change notification settings - Fork 35
/
vsnip.txt
323 lines (227 loc) · 10.5 KB
/
vsnip.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
*vim-vsnip* *vsnip*
V(SCode) Snip(pet) like plugin.
==============================================================================
CONTENTS *vsnip-contents*
INSTALL |vsnip-install|
VARIABLE |vsnip-variable|
FUNCTION |vsnip-function|
MAPPING |vsnip-mapping|
COMMAND |vsnip-command|
BUILT-IN VARIABLE |vsnip-built-in-variable|
LIMITATION |vsnip-limitation|
CHANGELOG |vsnip-changelog|
==============================================================================
INSTALL *vsnip-install*
You can use your favorite plugin manager.
>
" dein.vim
call dein#add('hrsh7th/vim-vsnip')
" vim-plug
Plug 'hrsh7th/vim-vsnip'
" neobundle
NeoBundle 'hrsh7th/vim-vsnip'
<
If you use `deoplete.nvim` or other supported integration, you can use `vim-vsnip-integ`.
>
" dein.vim
call dein#add('hrsh7th/vim-vsnip-integ')
" vim-plug
Plug 'hrsh7th/vim-vsnip-integ'
" neobundle
NeoBundle 'hrsh7th/vim-vsnip-integ'
<
If you want to know supported plugins, you can see https://github.com/hrsh7th/vim-vsnip-integ
==============================================================================
VARIABLE *vsnip-variable*
let g:vsnip_extra_mapping = v:true~
Enable or disable extra mappings.
let g:vsnip_snippet_dir = expand('~/.vsnip')~
Specify user snippet directory.
Also as buffer-local variable: `b:vsnip_snippet_dir`
let g:vsnip_snippet_dirs = []~
List of user snippet directories.
Also as buffer-local variable: `b:vsnip_snippet_dirs`
let g:vsnip_filetypes = {}~
Specify extended filetypes.
For example, you can extend `javascript` filetype with `javascriptreact` filetype.
>
let g:vsnip_filetypes = {}
let g:vsnip_filetypes.javascriptreact = ['javascript']
<
let g:vsnip_deactivate_on = g:vsnip#DeactivateOn.OutsideOfSnippet~
Specify when to deactivate the current snippet.
`g:vsnip#DeactivateOn.OutsideOfSnippet`:
Deactivate on edit the outside of snippet.
`g:vsnip#DeactivateOn.OutsideOfCurrentTabstop`:
Deactivate on edit the outside of current tabstop.
let g:vsnip_sync_delay = 0~
Specify delay time to sync same tabstop placeholder.
-1: No sync
0: Always sync
N: Debounce N milliseconds
let g:vsnip_choice_delay = 500~
Specify delay time to show choice candidates.
Sometimes choice completion menu is closed by auto-completion engine.
You can use this variable to solve this conflict.
let g:vsnip_namespace = ''~
Specify all snippet prefix's prefix.
It useful when you use auto-completion.
let g:vsnip_append_final_tabstop = v:true~
Specify whether to add a final tabstop.
==============================================================================
FUNCTION *vsnip-function*
vsnip#variable#register({VAR_NAME}, {FUNCREF}, [{OPTION}}])
Register your own custom variable resolver.
==============================================================================
MAPPING *vsnip-mapping*
You can use your favorite key to expand or jump snippet.
The below example uses '<Tab>' key.
>
" Expand
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
" Expand or jump
imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
" Jump forward or backward
imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.
" See https://github.com/hrsh7th/vim-vsnip/pull/50
nmap s <Plug>(vsnip-select-text)
xmap s <Plug>(vsnip-select-text)
nmap S <Plug>(vsnip-cut-text)
xmap S <Plug>(vsnip-cut-text)
<
==============================================================================
COMMAND *vsnip-command*
VsnipOpen~
:VsnipOpen [-format {type}]
:VsnipOpenEdit [-format {type}]
:VsnipOpenSplit [-format {type}]
:VsnipOpenVsplit [-format {type}]
Open snippet source file under `g:vsnip_snippet_dir`.
{type} is either 'snipmate' or 'vscode'. If omitted, it is 'vscode'.
VsnipYank~
Copy the given range formatted as json into the clipboard.
Use this command to yank the current line as a snippet with the keyword 'key'
and open the snippets file.
>
:VsnipYank key | VsnipOpen
<
==============================================================================
BULT-IN VARIABLE *vsnip-built-in-variable*
Basically, vsnip provides some of built-in variables that defined in VSCode or LSP spec.
The following variables can be used in the same way they are in VSCode:
`TM_SELECTED_TEXT` The currently selected text or the empty string
`TM_CURRENT_LINE` The contents of the current line
`TM_CURRENT_WORD` The contents of the word under cursor or the empty string
`TM_LINE_INDEX` The zero-index based line number
`TM_LINE_NUMBER` The one-index based line number
`TM_FILENAME` The filename of the current document
`TM_FILENAME_BASE` The filename of the current document without its extensions
`TM_DIRECTORY` The directory of the current document
`TM_FILEPATH` The full file path of the current document
`RELATIVE_FILEPATH` The relative (to the current working directory) file path of the current document
`CLIPBOARD` The contents of your clipboard
`WORKSPACE_NAME` The name of the opened workspace or folder
For inserting the current date and time:
`CURRENT_YEAR` The current year
`CURRENT_YEAR_SHORT` The current year's last two digits
`CURRENT_MONTH` The month as two digits (example '02')
`CURRENT_MONTH_NAME` The full name of the month (example 'July')
`CURRENT_MONTH_NAME_SHORT` The short name of the month (example 'Jul')
`CURRENT_DATE` The day of the month
`CURRENT_DAY_NAME` The name of day (example 'Monday')
`CURRENT_DAY_NAME_SHORT` The short name of the day (example 'Mon')
`CURRENT_HOUR` The current hour in 24-hour clock format
`CURRENT_MINUTE` The current minute
`CURRENT_SECOND` The current second
`CURRENT_SECONDS_UNIX` The number of seconds since the Unix epoch
For inserting line or block comments, honoring the current language:
`BLOCK_COMMENT_START` Example output: in PHP /* or in HTML <!--
`BLOCK_COMMENT_END` Example output: in PHP */ or in HTML -->
`LINE_COMMENT` Example output: in PHP //
In addition, vsnip provides the below custom variables too.
`VSNIP_CAMELCASE_FILENAME` The filename of the current document without its extensions in CamelCase format
${VIM:...Vim script expression...}~
You can use this variable for `Vim script interpolation`.
For example, the below snippet will be current filetype.
>
{
"filetype": {
"prefix": "filetype",
"body": "${VIM:&filetype}"
}
}
<
You can also using any Vim script expression.
>
{
"sum": {
"prefix": "sum",
"body": "${VIM:1 + 2}"
}
}
<
Currently, vsnip only once resolves variable at the snippet initialization.
==============================================================================
SNIPMATE SUPPORT *vsnip-snipmate-support*
Files with the extension 'snippets' in directories `g:vsnip_snippet_dir` or
`g:vsnip_snippet_dirs` are recognized as snippets with SnipMate-like syntax.
NOTE: This feature does not guarantee that SnipMate's snippet collection can
be read in its entirety. It is intended to provide an easy way for users to
write their own new snippet definitions.
The following two examples are equivalent.
In SnipMate format. >
snippet fn vim's function
function! $1($2) abort
$0
endfunction
<
In VSCode format. >
{
"fn": {
"prefix": "fn",
"body": [
"function! $1($2) abort",
"\t$0",
"endfunction"
],
"description": "vim's function"
}
}
<
You can also use the extends syntax. For example, the first line of
cpp.snippets should have this. >
extends c
<
==============================================================================
LIMITATION *vsnip-limitation*
Currently vsnip has below limitations.
1. placeholder transform feature is not supported.~
I plan to support it later.
2. if text diff has multiple candidates, always use last one.~
below snippet is not work for expected.
>
class $1${2: extends ${3:SuperClass}} {
$0
}
<
below one is work as expected.
>
class $1 ${2:extends ${3:SuperClass} }{
$0
}
<
3. if edit the placeholder that does not the current_tabstop, vsnip try to follow correctly but sometimes it makes unexpected result.~
For example, you expand `console.log(${1:foo}${2:bar}, ${2})`, remove `foo` and change `bar` without jump.
In this case, vsnip will detects `$1 is edited.` so vsnip does not sync $2 placeholder.
==============================================================================
CHANGELOG *vsnip-changelog*
2019/12/01~
- publish v2.
==============================================================================
vim:tw=78:ts=4:et:ft=help:norl: