sponsor Vim development Vim logo Vim Book Ad

template.vim : Simple and flexible template engine.

 script karma  Rating 28/14, Downloaded by 2569  Comments, bugs, improvements  Vim wiki

created by
thinca
 
script type
utility
 
description
*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.


Example:
If the template files are located as follows:

~/.vim/template
|-- doc
|   `-- template.txt
|-- plugin
|   `-- template.vim
|-- template.java
|-- template.rb
|-- template.vim
|-- template_spec.rb
`-- templateTest.java

Template is loaded as follows.

Open file                       Template that is loaded
---------                       -----------------------
foo.vim                         template.vim
plugin/foo.vim                  plugin/template.vim
Foo.java                        template.java
FooTest.java                    templateTest.java
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.

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

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:
https://github.com/thinca/vim-template
 
install details
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-template-0.3.0.zip 0.3.0 2012-06-02 7.3 thinca - autoloadize.
  - Added template#load().
  - Added template#search().
  - Added template#loading().
- Added [line] support to :Templateload.
- Use <nomodeline> if possible.
vim-template-0.2.1.zip 0.2.1 2010-06-10 7.0 thinca - It was made not to become an error even when 'verbose' was one or more and the template was not found.
- Execute the event without :silent.
vim-template-0.2.0.zip 0.2.0 2009-10-31 7.2 thinca Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github