我如何实际使用Vim函数的参数值? [英] How do I actually use the value of an argument to a Vim function?

查看:80
本文介绍了我如何实际使用Vim函数的参数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个简单的Vim函数,它将文件的名称作为参数,并将该文件的内容读入当前文档(与这个问题)。

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).

这是我第一次刺穿它:

fun! Tpl(tplfile)
  r c:\tpl\a:tplfile
endfun

这只是给我以下错误:

That just gives me the following error:


E484:无法打开文件c:\ tpl\a:tplfile p>

E484: Can't open file c:\tpl\a:tplfile

如何让函数实际使用tplfile参数的值?

How do I make the function actually use the value of the tplfile argument?

推荐答案

替换行:

Replace the line with:

exe 'r c:\tpl\' . a:tplfile

a:tplfile是一个字符串变量,所以要将它包含在命令中,必须将整个批次合并为一个字符串(使用''运算符),然后使用exe来运行命令

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 command

:help exe

一个无耻的插件),如果你想添加模板(如你链接的帖子所暗示的),我的文件模板插件有一个命令 AddTemplate 可以从当前光标位置的vimfiles / templates目录添加一个模板。但是,文档目前相当差,因此如果您决定使用它并遇到任何困难,请随时在我的网站上的地址向我发送电子邮件。

On 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 AddTemplate to 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.

这篇关于我如何实际使用Vim函数的参数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆