Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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
like image 235
MrDaniel Avatar asked Jan 22 '12 12:01

MrDaniel


1 Answers

One can prepare a string containing the target command, and then use :execute to run it:

:exe s:beginLine.','.s:endLine 'call Comment()'
like image 101
ib. Avatar answered Nov 18 '22 14:11

ib.