Let me suggest the following implementation.
vnoremap <silent> <leader>
function! ExpandRange()
norm! gvy
let n = matchlist(@", '\(\d\+\)\s*-\s*\(\d\+\)')[1:2]
if len(n) != 2 || +n[0] > +n[1]
return
end
exe 'norm! gvc' . join(range(n[0], n[1]), ',')
endfunction
If the range notation guarantees the absence of spaces around numbers, the second operator ExpandRange()can be simplified by using
split(),
let n = split(@", '-')
Note that the text denoting the range is placed in an unnamed register. If it is preferable to leave the register unaffected, change ExpandRange()it to preserve its state in advance and restore it later.
function! ExpandRange()
let [qr, qt] = [getreg('"'), getregtype('"')]
norm! gvy
let n = matchlist(@", '\(\d\+\)\s*-\s*\(\d\+\)')[1:2]
call setreg('"', qr, qt)
if len(n) != 2 || +n[0] > +n[1]
return
end
exe 'norm! gv"_c' . join(range(n[0], n[1]), ',')
endfunction
source
share