Support snippet templates and add help snippets
Add `autocmd` to automatically expand the `_template` snippet on the `BufNewFile` event, if the expansion fails because the `_template` snippet does not exist for the current `filetype` undo the changes. Do the same thing when the `filetype` changes to `help`, since these are `text` files to begin with the first `autocmd` has no effect.
This commit is contained in:
16
autoload/snippet.vim
Normal file
16
autoload/snippet.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
" Description: Expand snippet on file creation.
|
||||
|
||||
" Attempt to expand the _template snippet if this is a new file.
|
||||
" https://noahfrederick.com/log/vim-templates-with-ultisnips-and-projectionist
|
||||
function! snippet#template() abort
|
||||
" Return if non-empty buffer or file exists.
|
||||
if !(line('$') == 1 && getline('$') ==# '') || filereadable(expand('%'))
|
||||
return
|
||||
endif
|
||||
" Attempt to expand the _template snippet.
|
||||
execute "normal! i_template\<C-r>=UltiSnips#ExpandSnippet()\<CR>"
|
||||
if g:ulti_expand_res == 0
|
||||
" Expansions failed, undo insert.
|
||||
silent! undo
|
||||
endif
|
||||
endfunction
|
||||
Reference in New Issue
Block a user