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
One can prepare a string containing the target command,
and then use :execute
to run it:
:exe s:beginLine.','.s:endLine 'call Comment()'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With