I’m trying to write a simple Vim function that takes the name of a file as an argument and reads the contents of that file into the current document (related to this question).
Here’s my first stab at it:
fun! Tpl(tplfile)
r c:\tpl\a:tplfile
endfun
That just gives me the following error:
E484: Can’t open file c:\tpl\a:tplfile
How do I make the function actually use the value of the tplfile argument?
Replace the line with:
The a:tplfile is a string variable, so to include it in a command, you have to combine the whole lot into one string (with the ‘
.‘ operator) and then use exe to run the commandOn a related note (and a shameless plug), if you’re trying to add templates (as implied by the post you linked to), my file templates plugin has a command
AddTemplateto add a template from your vimfiles/templates directory at the current cursor location. However, the documentation is currently rather poor, so if you decide to use it and have any difficulties, feel free to drop me an email at the address on my website.