Skip to content

Instantly share code, notes, and snippets.

@voyeg3r
Created April 2, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voyeg3r/43247c5545936ad7756365d9e5678b4a to your computer and use it in GitHub Desktop.
Save voyeg3r/43247c5545936ad7756365d9e5678b4a to your computer and use it in GitHub Desktop.
ultisnips_custom
" File: ultisnips_custom.vim - Custom UltiSnips settings
" Maintainer: Sergio Araújo
" Oririnal Creator: Noah Frederick
" Last Change: abr 02 2019 17:24
" Place it at: after/plugin/ultisnips_custom.vim
"
" esse script está funcionando standalone
" ou seja sem interação com outros que não sejam
" os que já vem com o sistema e insere templates zsh, sh, python etc.
" We need python or python3 to run ultisnips
if !has("python") && !has("python3")
finish
endif
" This function is called by the autocommand at the end of the file
function! TestAndLoadSkel() abort
let filename = expand('%')
" Abort on non-empty buffer or extant file
"if !(line('$') == 1 && getline('$') == '')
if !(line('$') == 1 && getline('$') == '') || filereadable('%')
return
endif
" Load UltiSnips in case it was deferred via vim-plug
if !exists('g:did_plugin_ultisnips') && exists(':PlugStatus')
call plug#load('ultisnips')
doautocmd FileType
endif
" the function feedkys simulates the insert key sequence in order to call
" the template (skel)
execute 'call feedkeys("i_skel\<c-j>")'
endfunction
augroup ultisnips_custom
autocmd!
au Bufnewfile *.sh,*.zsh,*.html,*.css,*.py,*.tex,*.md :call TestAndLoadSkel()
"autocmd BufEnter *.sh,*.zsh,*.html,*.py execute 'call feedkeys("i_skel\<c-j>")'
augroup END
" vim: fdm=marker:sw=2:sts=2:et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment