e7e06a9f691a8977be828297b3ae6dd86f9682e6
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-snippets / Readme.md
1 # coc-snippets
2
3 Snippets solution for [coc.nvim](https://github.com/neoclide/coc.nvim)
4
5 ![2019-03-23 00_09_39](https://user-images.githubusercontent.com/251450/54837017-62891300-4d00-11e9-9e53-49742a1a33f2.gif)
6
7 _Snippet preview requires [neovim 0.4 or latest vim8](https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-to-make-preview-window-shown-aside-with-pum)_
8
9 It's capable of:
10
11 - Load UltiSnips snippets.
12 - Load snipmate snippets.
13 - Load VSCode snippets from coc extensions.
14 - Load VSCode snippets from custom directories.
15 - Load UltiSnips snippets from configured folder.
16 - Provide snippets as completion items.
17 - Provide expand and expandOrJump keymaps for snippet.
18 - Provide snippets list for edit snippet.
19 - Provide `snippets.editSnippets` command for edit user snippets of current filetype.
20
21 **Note:** some features of ultisnips and snipmate format snippets not supported, checkout [faq](#faq).
22
23 ## Why?
24
25 - Use same keys for jump placeholder.
26 - Nested snippet support.
27 - Always async, never slows you down.
28 - Improved match for complete items with TextEdit support.
29 - Edit snippets of current buffer by `:CocList snippets`, sorted by mru.
30
31 ## Install
32
33 In your vim/neovim, run command:
34
35 ```
36 :CocInstall coc-snippets
37 ```
38
39 ## Examples
40
41 ```vim
42 " Use <C-l> for trigger snippet expand.
43 imap <C-l> <Plug>(coc-snippets-expand)
44
45 " Use <C-j> for select text for visual placeholder of snippet.
46 vmap <C-j> <Plug>(coc-snippets-select)
47
48 " Use <C-j> for jump to next placeholder, it's default of coc.nvim
49 let g:coc_snippet_next = '<c-j>'
50
51 " Use <C-k> for jump to previous placeholder, it's default of coc.nvim
52 let g:coc_snippet_prev = '<c-k>'
53
54 " Use <C-j> for both expand and jump (make expand higher priority.)
55 imap <C-j> <Plug>(coc-snippets-expand-jump)
56 ```
57
58 Make `<tab>` used for trigger completion, completion confirm, snippet expand and jump like VSCode.
59
60 ```vim
61 inoremap <silent><expr> <TAB>
62       \ pumvisible() ? coc#_select_confirm() :
63       \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
64       \ <SID>check_back_space() ? "\<TAB>" :
65       \ coc#refresh()
66
67 function! s:check_back_space() abort
68   let col = col('.') - 1
69   return !col || getline('.')[col - 1]  =~# '\s'
70 endfunction
71
72 let g:coc_snippet_next = '<tab>'
73 ```
74
75 **Note:** `coc#_select_confirm()` helps select first complete item when there's
76 no complete item selected, neovim 0.4 or latest vim8 required for this function
77 work as expected.
78
79 ## Ultisnips features
80
81 Some ultisnips features are **not** supported:
82
83 - [x] Position check of trigger option, including `b`, `w` and `i`.
84 - [x] Execute vim, python and shell code in snippet.
85 - [x] `extends`, `priority` and `clearsnippets` command in snippet file.
86 - [x] Visual placeholder.
87 - [x] Placeholder and variable transform.
88 - [x] Expression snippet.
89 - [x] Automatic trigger snippet.
90 - [x] Context snippets.
91 - [x] Support loading snipmate snippets.
92 - [ ] Execute shell code with custom shabang (will not support).
93 - [ ] Automatic reformat snippet after change of placeholder (can't support).
94 - [ ] Format related snippet options, including `t`, `s` and `m` (can't support).
95 - [ ] Snippet actions (can't support).
96
97 **Note**: python regex in snippet are converted to javascript regex, however,
98 some regex patterns can't be supported by javascript, including
99 `\u` `(?s)` `\Z` `(?(id/name)yes-pattern|no-pattern)`.
100
101 ## Options
102
103 - `snippets.priority`: priority of snippets source, default `90`.
104 - `snippets.editSnippetsCommand`: Open command used for snippets.editSnippets command, use coc.preferences.jumpCommand by default.
105 - `snippets.trace`: Trace level of snippets channel.
106 - `snippets.enableStatusItem`: Enable status item in `g:coc_status` used for statusline.
107 - `snippets.extends`: extends filetype's snippets with other filetypes, example:
108
109   ```json
110   {
111     "cpp": ["c"],
112     "javascriptreact": ["javascript"],
113     "typescript": ["javascript"]
114   }
115   ```
116
117 - `snippets.userSnippetsDirectory`, Directory that contains custom user ultisnips snippets, use ultisnips in extension root by default.
118 - `snippets.shortcut`, shortcut in completion menu, default `S`.
119 - `snippets.autoTrigger`: enable auto trigger for auto trigger ultisnips snippets, default `true`.
120 - `snippets.triggerCharacters`: trigger characters for completion, default `[]`.
121 - `snippets.loadFromExtensions`: load snippets from coc.nvim extensions, default: `true`.
122 - `snippets.convertToSnippetsAction`: Add convert to snippet to code action list.
123 - `snippets.textmateSnippetsRoots`: absolute directories that contains textmate/VSCode snippets to load.
124 - `snippets.ultisnips.enable`: enable load UltiSnips snippets, default `true`.
125 - `snippets.ultisnips.usePythonx`: use `pythonx` for eval python code when possible, default `true`.
126 - `snippets.ultisnips.pythonVersion`: when `usePythonx` is false, python version to use for
127   python code, default to `3`.
128 - `snippets.ultisnips.directories`: directories that searched for snippet files,
129   could be subfolder in every \$runtimepath or absolute paths, default: `["UltiSnips"]`
130 - `snippets.snipmate.enable`: enable load snipmate snippets, default `true`.
131 - `snippets.snippets.author`: author name used for `g:snips_author`
132
133 ## Commands
134
135 - Use `:CocList snippets` to open snippets list.
136 - Use `:CocCommand snippets.editSnippets` to edit user snippet of current filetype.
137 - Use `:CocCommand snippets.openSnippetFiles` to open snippet files of current filetype.
138
139 ## F.A.Q
140
141 **Q:** How to check if a snippet successfully loaded?
142
143 **A:** Use command `:CocCommand workspace.showOutput snippets`
144
145 **Q:** Some ultisnips snippet not works as expected.
146
147 **A:** Reformat after change of placeholder feature can't be supported for now,
148 and some regex pattern can't be converted to javascript regex pattern, so the
149 snippet can be failed to load.
150
151 **Q:** Where to get snippets?
152
153 **A:** One solution is install [honza/vim-snippets](https://github.com/honza/vim-snippets) which is widely used.
154
155 **Q:** Do I need to install [Ultisnips](https://github.com/SirVer/ultisnips).
156
157 **A:** No! This extension is designed to work with or without Ultisnips, you can
158 still install Ultisnips, but this extension would not run any code or read
159 configuration from it.
160
161 **Q:** How to check jumpable or expandable at current position.
162
163 **A:** Use functions provided by coc.nvim: `coc#expandable()` `coc#jumpable()` and `coc#expandableOrJumpable()`.
164
165 **Q:** It doesn't load snippets from [vim-go](https://github.com/fatih/vim-go).
166
167 **A:** It uses `g:UltiSnipsSnippetDirectories` which is not supported, you can
168 add settings:
169
170 ```
171 snippets.ultisnips.directories: [
172   "UltiSnips",
173   "gosnippets/UltiSnips"
174 ],
175 ```
176
177 to load it.
178
179 **Q:** How could I add custom UltiSnips snippets.
180
181 **A:** You can create snippet files in folder: `$VIMCONFIG/coc/ultisnips`, use
182 command `:CocCommand snippets.editSnippets` to open user snippet of current
183 filetype.
184
185 ## License
186
187 MIT