function Get_string_between(string, start, end)
let str=""
"get length of string
let len =strlen(a:string)
"set the default values o start and end indexes to 0
let startIndex=0
let endIndex=0
"Get the index of start and end characters
let i =0
while i < len
if a:string[i] == a:start && startIndex == 0
let startIndex =i
elseif a:string[i] == a:end && endIndex == 0
let endIndex =i
endif
let i += 1
endwhile
echo "StartIndex: ". startIndex
echo "endIndex: ". endIndex
let i =startIndex+1
while i < endIndex
let str .= a:string[i]
let i +=1
endwhile
return str
endfunction
1条答案
按热度按时间lrl1mhuk1#
在研究了一个答案之后,我找到了一个答案,答案是默认情况下
expand('<cword>')
返回特殊字符之间的单词,如“〈”或“”......但如果我想获得两个索引之间的字符组,我们可以编写一个函数来完成这项工作