[vim/vim] Visual selection is not highlighted at the cursor position (PR #21317)

10 views
Skip to first unread message

Shane Harper

unread,
Sep 15, 2026, 8:01:55 AM (10 days ago) Sep 15
to vim/vim, Subscribed

Problem: In a terminal the character under the cursor is normally not shown as part of the visual selection.
Solution: Don't set "noinvcur" in win_line().

The problem did not occur in the GUI, only in a terminal.

The name "noinvcur" ("don't invert the cursor") was misleading: the variable did not affect the cursor, but whether the character under the cursor could be displayed as part of the visual selection.

The "noinvcur" handling may have been meant to help during a visual selection when Visual is shown in reverse video and the terminal draws the cursor by inverting the character under it, as otherwise the character under the cursor would not look highlighted like the rest of the selection. But Vim cannot know in general how a terminal draws the cursor, and when either the cursor is not drawn by inverting the character under it or Visual is not shown in reverse video, the handling just left a character of the visual selection unhighlighted.

Claude Opus 5 suggested deleting the fromcol_prev and vcol_prev variables from win_line(); I wrote all of the code changes.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/21317

Commit Summary

  • e5e3aeb Visual selection is not highlighted at the cursor position
  • 5798446 Delete noinvcur variable in win_line().
  • 160a995 Delete fromcol_prev variable in win_line().
  • 57911a6 Delete vcol_prev variable from win_line().
  • b42e635 Small simplification. Note: wlv.tocol is never negative.
  • b25ab70 Add Test_charwise_visual_hl_inclusive_and_exclusive_selection.

File Changes

(53 files)

Patch Links:

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21317@github.com>

zeertzjq

unread,
Sep 15, 2026, 8:04:33 AM (10 days ago) Sep 15
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#21317)

I think the problem here is that highlighting the cursor position may make the cursor invisible.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21317/c5679840347@github.com>

Shane Harper

unread,
Sep 15, 2026, 8:58:12 AM (10 days ago) Sep 15
to vim/vim, Subscribed
shaneharper left a comment (vim/vim#21317)

I think the problem here is that highlighting the cursor position may make the cursor invisible.

One case where it might be worse is an underline or bar cursor whose color is the same as (or similar to) Visual's background color.

Even where the cursor isn't distinguishable from the selection, its position is usually easy to follow. In a character-wise selection it's at one end of the selection, and in a line-wise selection its column doesn't affect what's selected. On the other hand, leaving the character under the cursor unhighlighted makes the selection look wrong with many combinations of Visual highlighting and cursor style.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21317/c5680537925@github.com>

Christian Brabandt

unread,
Sep 15, 2026, 2:01:08 PM (9 days ago) Sep 15
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21317)

Hm, we used to have Visual setting reverse until 59bafc8 (v9.1.0068) when the terminal did not have at least 8 colors. Perhaps that's why this was set initially?

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21317/c5685372435@github.com>

Shane Harper

unread,
Sep 15, 2026, 10:00:18 PM (9 days ago) Sep 15
to vim/vim, Subscribed
shaneharper left a comment (vim/vim#21317)

Hm, we used to have Visual setting reverse until 59bafc8 (v9.1.0068) when the terminal did not have at least 8 colors. Perhaps that's why this was set initially?

That seems likely - the "noinvcur" code looks like it was written assuming Visual would be shown in reverse video. That code existed in v7.0001 (the start of Vim's git history) when Visual was term=reverse cterm=reverse for every terminal.

On a terminal where Visual is still shown in reverse video, the cursor can usually be told apart from the selection without relying on a different color, e.g. a blinking cursor, or an underline cursor drawn by inverting pixels.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21317/c5690877880@github.com>

Christian Brabandt

unread,
Sep 16, 2026, 2:16:39 PM (8 days ago) Sep 16
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21317)

alright thanks. I think this is fine

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21317/c5702344318@github.com>

Reply all
Reply to author
Forward
0 new messages