如何从另一个函数中调用具有使用局部变量范围的 Vimscript 函数?
这是我正在使用的一个例子。它的目的是向文件添加样板,然后使用 Vim BlockComment()
插件函数注释掉这些行。目标是在从文件读取之前和完成从文件读取之后标记行号,以便我可以注释掉刚刚插入的行范围。
但是,我正在花时间弄清楚应该使用什么语法来指示该范围。下面的注释行是我尝试使用变量调用给定范围的函数。注释部分有语法错误,但是,如果我提供如下所示的硬编码范围,则脚本可以正常工作。在这种情况下,我们如何将我的范围作为变量放入?
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
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. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以准备一个包含目标命令的字符串,
然后使用
:execute
运行它:One can prepare a string containing the target command,
and then use
:execute
to run it: