diff options
-rw-r--r-- | autoload/sonictemplate.vim | 23 | ||||
-rw-r--r-- | template/go/pattern.stpl | 18 |
2 files changed, 34 insertions, 7 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 91f45df..c543b20 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -333,19 +333,28 @@ function! sonictemplate#postfix() let c = substitute(c, '{{$' . i . '}}', ml[i], 'g') endfor let indent = matchstr(line, '^\(\s*\)') - if len(indent) && (&expandtab || (&shiftwidth && &tabstop != &shiftwidth) || indent =~ '^ \+$') - let c = substitute(c, "\t", repeat(' ', min([len(indent), &shiftwidth])), 'g') - elseif &expandtab || (&shiftwidth && &tabstop != &shiftwidth) - let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g') - endif if line !~ '^\s*$' let lhs = col('.') > 1 ? line[:col('.')-2] : '' let rhs = line[len(lhs):] let lhs = lhs[len(indent):] let c = lhs . c . rhs endif - call setline('.', line) - silent! exe "normal! a\<c-r>=c\<cr>" + if c =~ "\n" + let c = indent . substitute(substitute(c, "\n", "\n".indent, 'g'), "\n".indent."\n", "\n\n", 'g') + if len(indent) && (&expandtab || (&shiftwidth && &tabstop != &shiftwidth) || indent =~ '^ \+$') + let c = substitute(c, "\t", repeat(' ', min([len(indent), &shiftwidth])), 'g') + elseif &expandtab || (&shiftwidth && &tabstop != &shiftwidth) + let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g') + endif + call setline('.', line) + if line('.') < line('$') + silent! normal! dd + endif + silent! put! =c + else + call setline('.', line) + silent! exe "normal! a\<c-r>=c\<cr>" + endif if stridx(c, '{{_cursor_}}') != -1 silent! call search('{{_cursor_}}\zs', 'w') silent! foldopen diff --git a/template/go/pattern.stpl b/template/go/pattern.stpl new file mode 100644 index 0000000..45c3b02 --- /dev/null +++ b/template/go/pattern.stpl @@ -0,0 +1,18 @@ +\(\S\+\)\.var$ + var {{$1}} = {{_cursor_}} + +\(\S\+\)\.iferr$ + if {{$1}} != nil { + return err + } + {{_cursor_}} + +\(\S\+\)\.fatal$ + if {{$1}} != nil { + log.Fatal(err) + } + {{_cursor_}} + +\(\S\+\)\.log$ + log.Println({{$1}}) + {{_cursor_}} |