I've read vim-wiki about dynamic templates and I want similar, simple "template-system". I've created a function:
function! Read_template(file)
execute '0r /home/zsolt/.vim/skeletons/'.a:file
%substitute#\[:EVAL:\]\(.\{-\}\)\[:END:\]#\=eval(submatch(1))#ge
%substitute#\[:READ:\]\(.\{-\}\)\[:END:\]#??????#ge
endfunction
I want to include a file from a template. The EVAL
works well but how can I solve the READ
function? It isn't important to eval the included file.
An example:
main.tex
:
\documentclass[a4paper]{article}
....
exam.tex
:
% Created [:EVAL:]strftime('%Y. %B. %d.')[:END:]
[:READ:]/path/of/main/main.tex[:READ:]
I exec Read_template("exam.tex")
and want that exam.tex
includes main.tex
.
How can I do this?
You'll need to read the file and insert its contents. As you cannot use :read
(it will read entire lines and cannot be called from within a substitution), you have to use the lower-level readfile()
Vimscript function, like this:
%substitute#\[:READ:\]\(.\{-\}\)\[:END:\]#\=join(readfile(submatch(1)),"\n")/#ge