diff --git a/vimrc b/vimrc index 41e4ef5..a7ca438 100644 --- a/vimrc +++ b/vimrc @@ -107,6 +107,67 @@ end " === GENERAL UTILITIES === +" --- TEXT SNIPPETS --- + +" -- Global -- + +if !exists('s:snippets') + let s:snippets = {} +end + +function! s:make_snippet(name, lines) + let s:snippets[a:name] = a:lines +endfun + +function! s:make_snippet_range(name, line_start, line_end) + call s:make_snippet(a:name, getline(a:line_start, a:line_end)) +endfun + +function! s:insert_snippet(name) + for line in get(s:snippets, a:name, []) + put =line + endfor +endfun + +function! MkSnip(name, str) + call s:make_snippet(a:name, split(a:str, '\n')) +endfun + +command! -nargs=1 Snippet call s:insert_snippet() +command! -range -nargs=1 MkSnippet call s:make_snippet_range(, , ) + +" -- Filetype -- + +if !exists('s:ft_snippets') + let s:ft_snippets = {} +end + +function! s:make_ft_snippet(ft, name, lines) + if !get(s:ft_snippets, a:ft, 0) + let s:ft_snippets[a:ft] = {} + end + let s:ft_snippets[a:ft][a:name] = a:lines +endfun + +function! s:make_ft_snippet_range(ft, name, line_start, line_end) + call s:make_ft_snippet(a:ft, a:name, getline(a:line_start, a:line_end)) +endfun + +function! s:insert_ft_snippet(ft, name) + for line in get(get(s:ft_snippets, a:ft, {}), a:name, []) + put =line + endfor +endfun + +function! MkFTSnip(ft, name, str) + call s:make_ft_snippet(a:ft, a:name, split(a:str, '\n')) +endfun + +command! -nargs=1 FTSnippet call s:insert_ft_snippet(&filetype, ) +command! -range -nargs=1 FTMkSnippet call s:make_ft_snippet_range(&filetype, , , ) + +" --- AUTO CLOSE --- + function! s:autoClose_HelperOpen(open, close) let next_c = getline(".")[col(".")-1] if match(next_c, "\s")