Add text snippets commands

This commit is contained in:
Talia 2018-05-11 08:19:32 +02:00
parent 6447dc5fa1
commit 5f7a6f7ae8

61
vimrc
View file

@ -107,6 +107,67 @@ end
" === GENERAL UTILITIES === " === 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(<f-args>)
command! -range -nargs=1 MkSnippet call s:make_snippet_range(<f-args>, <line1>, <line2>)
" -- 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, <f-args>)
command! -range -nargs=1 FTMkSnippet call s:make_ft_snippet_range(&filetype, <f-args>, <line1>, <line2>)
" --- AUTO CLOSE ---
function! s:autoClose_HelperOpen(open, close) function! s:autoClose_HelperOpen(open, close)
let next_c = getline(".")[col(".")-1] let next_c = getline(".")[col(".")-1]
if match(next_c, "\s") if match(next_c, "\s")