-
-
Couldn't load subscription status.
- Fork 964
Using snippets
Coc has snippets support in different ways:
- Snippet completion items from different vim snippet plugins, by use extension like: coc-ultisnips and coc-neosnippet.
- Snippet kind of completion item from language servers, which are snipmate format.
- Snippet completion items from coc extensions that contribute VSCode snippets.
Complete item of snippet kind would be shown with ~ appended in label by default:

Note: when snippet format of complete item is set on completion resolve, you won't see ~, since it's impossible for vim to update label of complete item during completion.
The snippet is designed to expand only when the completionDone is triggered by using <C-y> for confirm, so that user could decide expand the snippet or not. To make <cr> for confirm completion, add
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<CR>"to your init.vim.
A snippet session would cancel under the following conditions:
-
InsertEntertriggered outside snippet. - Content change at final placeholder.
- Content added after snippet.
- Content changed in a snippet but not happens to a placeholder.
You can nest snippets in an active snippet session, just like VSCode.
To navigate forward/backward of a snippet placeholder, use <C-j> and <C-k>.
Vim global variable g:coc_snippet_next and g:coc_snippet_prev can be used to change the key-mapping.
If you don't like ~ as snippet indicator of complete item in completion menu, you can change that by using coc.preferences.snippetIndicator in your coc-settings.json.
To make snippet completion work just like VSCode, add:
inoremap <expr> <TAB> pumvisible() ? "\<C-y>" : "\<TAB>"
let g:coc_snippet_next = '<TAB>'
let g:coc_snippet_prev = '<S-TAB>'to your .vimrc.
And add:
to your coc-settings.json.
If you want to load VSCode snippets from coc extensions, install the coc-snippets extension, and then install a VSCode snippet extension from GitHub with a command like:
:CocInstall https://github.com/andys8/vscode-jest-snippets.git#master
To open a file with a snippet related filetype, like foo.js as javascript, you only need to type part of the prefix characters.