Fandom

Vim Tips Wiki

Insert template files into buffer

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 624 Printable Monobook Previous Next

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 header.html and 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).

NotesEdit

  • The filenames are not embedded in comments because they could be easily overlooked later.
  • refile stands for reference file

CommentsEdit

Also on Fandom

Random Wiki