简体   繁体   English

如何从另一个函数中调用具有使用局部变量的范围的 Vimscript 函数?

[英]How to call a Vimscript function that has a range using local variables, from within another function?

Here is an example that I am working with.这是我正在使用的示例。 It is intended to add a boilerplate to a file, and then comment out those lines using Vim BlockComment() plugin function.它旨在向文件添加样板,然后使用 Vim BlockComment()插件函数注释掉这些行。 The goal is to mark the line number before I read from the file and after I have completed reading from the file, so that I can comment out the range of lines just inserted.目标是在我读取文件之前和完成读取文件之后标记行号,以便我可以注释掉刚刚插入的行的范围。

However, I am having a time figuring out what the syntax should be to indicate that range.但是,我有时间弄清楚指示该范围的语法应该是什么。 The commented line below is my attempt to call a function with a given range using variables.下面的注释行是我尝试使用变量调用具有给定范围的函数。 The commented part has a syntax error, but, if I provide a hard-coded range as shown below, the script works.注释部分有一个语法错误,但是,如果我提供如下所示的硬编码范围,脚本就可以工作。 How do we put my range in as a variable in this case?在这种情况下,我们如何将我的范围作为变量放入?

function! AddBoilerPlate()
    let s:beginLine = line(".")
    r /Users/danieljbrieckjr/myBolierPlate.txt
    exe "normal! joDate Created: " . strftime("%B %d, %Y")
    exe "normal! oLast Modified: " . strftime("%B %d, %Y")

    let s:endLine = line(".")

"--------------------------------------------------
"     s:beginLine, s:endLine call Comment()
"-------------------------------------------------- 

    1,3 call Comment()

endfunction

可以准备一个包含目标命令的字符串,然后使用:execute来运行它:

:exe s:beginLine.','.s:endLine 'call Comment()'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM