在vimscript函数中使用局部变量调用具有范围的vimscript函数

MrD*_*iel 4 vim boilerplate

这是我正在使用的一个例子.它旨在向文件添加样板,然后注释掉刚刚使用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
Run Code Online (Sandbox Code Playgroud)

ib.*_*ib. 11

在这种情况下,可以准备一个包含目标命令的字符串,然后用:execute它来运行它,

:exe s:beginLine.','.s:endLine 'call Comment()'
Run Code Online (Sandbox Code Playgroud)