[vim/vim] cursorline causes an extra column to be highlighted (#7883)

68 views
Skip to first unread message

Chuan Wei Foo

unread,
Feb 20, 2021, 2:49:43 PM2/20/21
to vim/vim, Subscribed

Describe the bug
When using set cursorline with cursorlineopt set to either both, line, or screenline, an extra column will be highlighted on the cursor's line when using matchadd() to highlight multiple lines. The problem does not occur when set cursorline is used with set cursorlineopt=number.

To Reproduce

Good behavior (without set cursorline):

  1. Run vim --clean

  2. Insert a few lines of text into the buffer.

  3. :call matchadd('Visual', '\_.*'). Result:

    Correct highlighting of lines

Bad behavior (with set cursorline):

  1. Run vim --clean

  2. :set cursorline

  3. Insert a few lines of text into the buffer.

  4. Position the cursor on the first line of the buffer and :call matchadd('Visual', '\_.*'). Result:

    Wrong highlighting of lines (extra column is highlighted)

  5. Exit Vim, repeat steps 1-3, position the cursor on the second line of the buffer and :call matchadd('Visual', '\_.*'). Result:

    Wrong highlighting of lines (an extra column is highlighted)

    Notice how an extra column is highlighted at the end of the cursor's line.

Expected behavior
There should be no extra highlighted column at the end of the cursor's line.

Environment (please complete the following information):

  • Vim version: 8.1.2269
  • OS: Ubuntu 20.04
  • Terminal: GNOME Terminal


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Feb 20, 2021, 3:57:53 PM2/20/21
to vim/vim, Subscribed

Interestingly, when matching with ".*" then it's the other way around, at the cursor line the last character is not highlighted.

Chuan Wei Foo

unread,
Feb 20, 2021, 8:36:54 PM2/20/21
to vim/vim, Subscribed

Interestingly, when matching with ".*" then it's the other way around, at the cursor line the last character is not highlighted.

Screenshot of :set cursorline | call matchadd('Visual', '.*'):

Incorrect highlighting

Bram Moolenaar

unread,
Feb 21, 2021, 7:48:55 AM2/21/21
to vim/vim, Subscribed

I would argue that searching for "_." includes the line separator, thus highlighting the extra character would be correct. Thus the highlight in the cursor line is OK. Other lines stop too early.
".
" actually does not include the line separator, but after matching the whole line of text there is an empty match at the end of the line, and for an empty match one character extra is highlighted. ".+" does not have the extra match. I managed to fix that part, the other one is not so easy.

Bram Moolenaar

unread,
Feb 22, 2021, 4:14:36 PM2/22/21
to vim/vim, Subscribed

Closed #7883 via 41f0895.

Reply all
Reply to author
Forward
0 new messages