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
可以准备一个包含目标命令的字符串,然后使用:execute
来运行它:
:exe s:beginLine.','.s:endLine 'call Comment()'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.