aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2011-10-28 10:22:20 +0900
committermattn <mattn.jp@gmail.com>2011-10-28 10:22:20 +0900
commit65d61396541c563ede37de7abd052453af5e5648 (patch)
tree9cb7c84592e8524f73f54e7d3a4913b255c536e2
parentcb98d68e685247afe5ce09a9da734acda9669875 (diff)
downloadvim-sonictemplate-65d61396541c563ede37de7abd052453af5e5648.tar.gz
vim-sonictemplate-65d61396541c563ede37de7abd052453af5e5648.tar.bz2
vim-sonictemplate-65d61396541c563ede37de7abd052453af5e5648.zip
add {{_if_:foo;bar;baz}}.
-rw-r--r--doc/template-vim.txt9
-rw-r--r--plugin/template.vim4
2 files changed, 11 insertions, 2 deletions
diff --git a/doc/template-vim.txt b/doc/template-vim.txt
index 0e49f8c..c407eff 100644
--- a/doc/template-vim.txt
+++ b/doc/template-vim.txt
@@ -167,9 +167,16 @@ Note that I'm using pathogen-vim.
|{{_expr_:xxx}}| : expression in vimscript.
- For example, "Current Time:|{{_expr_:strftime('%c')}}|" will be
+ For example: "Current Time:|{{_expr_:strftime('%c')}}|" will be
>
Current Time: 2011/10/27 20:19:00
<
+ |{{_if_:expr;foo;bar}}| : ternary operator
+
+ For example: When today is saturday,
+ "Today is |{{_if_:strftime('%w')%6;OrdinaryDay;Holiday}}|" will be
+>
+ Today is Holiday
+<
==============================================================================
vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0:
diff --git a/plugin/template.vim b/plugin/template.vim
index a6cbc59..dd742a5 100644
--- a/plugin/template.vim
+++ b/plugin/template.vim
@@ -70,6 +70,7 @@ function! s:Template(name) abort
let val = input(var . ":")
let c = substitute(c, '\V{{_input_:'.var.'}}', '\=val', 'g')
endfor
+ let c = substitute(c, '{{_if_:\(.\{-}\);\(.\{-}\)\(;\(.\{-}\)\)\{-}}}', '\=eval(submatch(1))?submatch(2):submatch(4)', 'g')
let c = substitute(c, '{{_expr_:\(.\{-}\)}}', '\=eval(submatch(1))', 'g')
if len(c) == 0
return
@@ -96,8 +97,9 @@ function! s:Template(name) abort
if stridx(c, '{{_cursor_}}')
silent! call search('{{_cursor_}}', 'w')
silent! s/{{_cursor_}}//g
- silent! exe "normal! \<c-o>"
endif
+ silent! exe "normal! \<c-o>"
+ startinsert
endfunction
" vim:ts=4:sw=4:et