Simple and flexible template engine.
Vim script
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a mirror of

*template* is a Vim plugin to read the template file automatically when the
edit of the file is newly started.  Template file is selected to match the
file name to open. Also, you can run any command after the open.

If the template files are located as follows:

 |-- doc
 |   `-- template.txt
 |-- plugin
 |   `-- template.vim
 |-- template.rb
 |-- template.vim
 |-- template_spec.rb

Template is loaded as follows.

Open file                       Template that is loaded
---------                       -----------------------
foo.vim                         template.vim
plugin/foo.vim                  plugin/template.vim                        
foo.rb                          template.rb
foo_spec.rb                     template_spec.rb
foo.txt                         (None)
doc/foo.txt                     doc/template.txt

And, you can execute commands when template loaded.

Defines replacing keywords:
    autocmd User plugin-template-loaded call s:template_keywords()
    function! s:template_keywords()
      %s/<+FILE NAME+>/\=expand('%:t')/g
      " And more...

Evaluate by vim and expand the inside of <%= %>:
    autocmd User plugin-template-loaded
    \ silent %s/<%=\(.\{-}\)%>/\=eval(submatch(1))/ge

Expand the date it is written in the following template.
    <%= strftime('%Y-%m-%d') %>

Move the cursor to <+CURSOR+>:
    autocmd User plugin-template-loaded
    \    if search('<+CURSOR+>')
    \  |   execute 'normal! "_da>'
    \  | endif

Filtered by an external command:
    autocmd User plugin-template-loaded silent! :%!erb
    autocmd User plugin-template-loaded silent! :%!php

Latest Version: