sponsor Vim development Vim logo Vim Book Ad

vimgen : vim inline generator / template expander

 script karma  Rating 69/18, Downloaded by 797    Comments, bugs, improvements  Vim wiki

created by
Bastian Mathes
script type
Vimgen is a simple template system that works inside a VIM buffer. The
input is a region of text. Everything until the first empty line in this
region is considered the data section, everything below the first empty line
is the template section. See included help file.

The data section of the input (everything until the first empty line) has to
be a valid VIM dictionary. Newlines ("\n") but no empty lines can be inserted for
better readability (they are ignored). The data section is evaluated using VIM's
eval function, hence it can include VIM functions, e.g. from the included range_date.vim.

The template section of the input (everything below the first empty line) is the
desired output (including newlines etc.) that has to be enriched/multiplied by the
data using vimgen tags.

There are only three types of tags:

this tags loop over the variable 'var' which has to be
a list. Inside the loop «var» references the element of
the current iteration

used inside a loop over 'var'. The test/tags that are surrounded
by this tag are ignored in the first iteration of the loop. This
is useful for enumerations (see |vimgen-examples|)

this tag is replaced with the variable 'var', where 'var'
either has only one value or the tag is surrounded by
a loop iterating over 'var'. In case of nested dictionaries,
a dot notation is used, e.g. a.b.c

Example of a template for a partitioned oracle table:

{'date':Range_month("200712","200803"), 'code':[['foo','0OF'',''OFF2'],['bar','RAB']]}

CREATE TABLE test_table
    (date_id  DATE NOT NULL, id1 NUMBER, id2 NUMBER)
  «!»PARTITION testpart_«date» VALUES LESS THAN (TO_DATE('«date»01', 'YYYYMMDD'))
    «!»SUBPARTITION testpart_«date»_«code[0]» VALUES ('«code[1]»')«-»

CREATE TABLE test_table
    (date_id  DATE NOT NULL, id1 NUMBER, id2 NUMBER)
  PARTITION testpart_200712 VALUES LESS THAN (TO_DATE('20071201', 'YYYYMMDD'))
    SUBPARTITION testpart_200712_foo VALUES ('0OF','OFF2'),
    SUBPARTITION testpart_200712_bar VALUES ('RAB')
  PARTITION testpart_200801 VALUES LESS THAN (TO_DATE('20080101', 'YYYYMMDD'))
    SUBPARTITION testpart_200801_foo VALUES ('0OF','OFF2'),
    SUBPARTITION testpart_200801_bar VALUES ('RAB')
  PARTITION testpart_200802 VALUES LESS THAN (TO_DATE('20080201', 'YYYYMMDD'))
    SUBPARTITION testpart_200802_foo VALUES ('0OF','OFF2'),
    SUBPARTITION testpart_200802_bar VALUES ('RAB')
  PARTITION testpart_200803 VALUES LESS THAN (TO_DATE('20080301', 'YYYYMMDD'))
    SUBPARTITION testpart_200803_foo VALUES ('0OF','OFF2'),
    SUBPARTITION testpart_200803_bar VALUES ('RAB')
install details
This is a vimball, just edit vimgen.vba and source everything
:so %

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
vimgen.vba 0.1.1 2008-04-23 7.0 Bastian Mathes small error correction
vimgen.vba 0.1 2008-03-26 7.0 Bastian Mathes Initial upload
ip used for rating:

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.
SourceForge.net Logo