这是我正在使用的一个例子。它的目的是向文件添加样板,然后使用 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
可以准备一个包含目标命令的字符串, 然后使用
:execute
运行它:
:exec s:beginLine..','..s:endLine 'call Comment()'