I was wondering if there was a syntax for specifying a range of relative lines in vim/ex that does not give 'invalid range' and instead gets as many lines as it can.
Select relative range, ignoring invalid line numbers
268 views Asked by 0x777C At
2
There are 2 answers
0
On
My CmdlineSpecialEdits plugin has (among many others) a CTRL-G + mapping that changes relative ranges like .-5,.+5 to absolute line numbers and vice versa. It also corrects addressing out of bounds (<= 0 and larger than the last line number) and backwards ranges.
There is no built-in way, but you can resolve the relative ranges into absolute line numbers yourself, and then limit the range to the available lines with
:help min()and:help max(). So, for example, the following relative range:is equivalent to this:
would be converted into this: