Insert template files into buffer
From Vim Tips Wiki
created 2003 · complexity intermediate · author A.L Marin · version 5.7
While editing HTML I want to use template files to be expanded on my html pages. Say for example I have something like this on my html file:
#refile=path/templates/header.html <p>html code here</p> <p>more html code here...</p> #refile=path/templates/footer.html
I want the files
footer.html to be inserted on my page, you can do this with the following command:
command! -range=% Refile <line1>,<line2>g/^#refile=/exe ":r " . strpart(getline("."), 8) | normal! kdd " 'Read_vim' / Revise by reading in file templates. " Get the string part after the = sign, on line(s) which " *begin* with #revim= , and use that to read in said file " -------------------- (kdd deletes the # line; put comments in templates).
- The filenames are not embedded in comments because they could be easily overlooked later.
- refile stands for reference file