inkarkat / vim-mark

Highlight several words in different colors simultaneously.
http://www.vim.org/scripts/script.php?script_id=2666
262 stars 32 forks source link

":NMark pattern" produces "E16: Invalid range" when N exceeds number of lines in buffer #32

Closed ghgary closed 4 years ago

ghgary commented 4 years ago

When I execute the :Mark command with a highlight group number and a patterns, as for example,

:3Mark /hello/

and there are fewer than 3 lines in the buffer, Vim displays the error message

E16: Invalid range

I am using Mark-3.1.0, ingo-library-1.041 and Vim 8.2.1081 on Ubuntu 18.04. The behavior is the same using Vim 8.2.1101 on Windows 10.

The bug appears to be due to the definition of the :Mark command in plugin/mark.vim. The :Mark command is defined with the -range option, so Vim assumes that the number preceding the command is a range. When a highlight group number is used in front of the :Mark command, Vim sees this as a line number and if the line number does not exist, Vim issues the error message.

This can be fixed by replacing the -range option with the -count option, since only the parameter is used in the command. I have tried this fix and it has it worked so far.

inkarkat commented 4 years ago

Thanks for your report; you suggested fix of using -count would work most of the time; unfortunately, it will eat a number at the beginning of an argument, so e.g. :3Mark 99balloons would highlight balloons with mark group 99. Fortunately, Vim has introduced a :command -addr=other modifier that covers this case.

inkarkat commented 4 years ago

That problem has been introduced by a backward-incompatible tightening of rules in Vim 8.1.1241. I had addressed the problem on the development branch in 6016b283781f1f13f742f470e29c4e69b2741117; it (until now) hasn't been released yet.

I've just prepared a version 3.1.1 update; you also need to update the ingo-library dependency to version 1.042 (also just released).