Snippets with CoC

From EdWiki

Revision as of 03:48, 24 February 2021 by Jshankar (Talk | contribs) (Commands)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Plug 'honza/vim-snippets'

Make sure you install CoC, video is available for that here

After setting up CoC you can install with:

:CocInstall coc-snippets


You can create a config file and add the following:

" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for select text for visual placeholder of snippet.
vmap <C-j> <Plug>(coc-snippets-select)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)

Add your own snippets

Edit coc-settings.json and add the following:

"snippets.userSnippetsDirectory": "~/.config/nvim/snips", After that you can add a file like this:

mkdir ~/.config/nvim/snips
touch ~/.config/nvim/snips/markdown.snippets # <- doesn't have to be called markdown


You'll be able to notice it's a snippet from the ~ character

Auto complete should feel very familiar, refer to the earlier bindings you set.

To list all snippets for a current file:

:CocList snippets
:CocCommand snippets.editSnippets
:CocCommand snippets.openSnippetFiles

Repo Links