Highlight character under cursor in visual mode

188 views
Skip to first unread message

Kyle Marek

unread,
Jul 25, 2022, 4:05:32 AM7/25/22
to vim...@googlegroups.com
Hello,

Why doesn't vim apply the Visual highlight to the character *at* the
cursor position in visual mode? Block cursors are nice and all, but
sometimes you're at a tty where you have an underline, and the lack of
highlighting is confusing.

Is there a way to get vim to include the character under the cursor for
visual highlighting?

Thank you,

Kyle Marek

Bram Moolenaar

unread,
Jul 25, 2022, 5:33:38 AM7/25/22
to vim...@googlegroups.com, Kyle Marek
Short answer: no.

Background: Various terminals behave differently about how the cursor is
displayed. Also the cursor shape may depend on whether the terminal is
in focus or not. To avoid that the cursor disappears (which is a big
problem) the Visual highlighting is not applied to the character under
the cursor. That may look a little bit strange (small problem) but
you'll get used to it.

--
hundred-and-one symptoms of being an internet addict:
113. You are asked about a bus schedule, you wonder if it is 16 or 32 bits.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Kyle Marek

unread,
Jul 25, 2022, 11:47:44 PM7/25/22
to vim...@googlegroups.com, Bram Moolenaar
On 7/25/22 5:33 AM, Bram Moolenaar wrote:
>> Why doesn't vim apply the Visual highlight to the character *at* the
>> cursor position in visual mode? Block cursors are nice and all, but
>> sometimes you're at a tty where you have an underline, and the lack of
>> highlighting is confusing.
>>
>> Is there a way to get vim to include the character under the cursor for
>> visual highlighting?
> Short answer: no.
>
> Background: Various terminals behave differently about how the cursor is
> displayed. Also the cursor shape may depend on whether the terminal is
> in focus or not. To avoid that the cursor disappears (which is a big
> problem) the Visual highlighting is not applied to the character under
> the cursor.

Okay. Thank you for clarifying this.

> That may look a little bit strange (small problem) but
> you'll get used to it.

You say that, but it has been annoying me and confusing my friends for
at least 5 years.

That being said, I put the following together for setting the Linux tty
/ VGA cursor size, enabling the use of a block cursor for visual mode.
Regarding my comments, I made some assumptions about vim behavior based
on observations:

" set cursors for linux tty
"
" See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/VGA-softcursor.txt?h=v2.6.12
if &term =~ "linux"

" start insert mode (using standard underline in linux tty)
let &t_SI = "\e[?2c"
" start replace mode (using thick underline in linux tty)
let &t_SR = "\e[?3c"
" end insert or replace mode (block cursor shape)
let &t_EI = "\e[?8c"

" vim only uses t_EI when entering normal mode by leaving insert mode,
" and instead uses t_VS at the very beginning. However, vim doesn't send
" t_VS if t_vs is not also set. Set them both to t_EI so we get a
" block cursor when vim starts.
let &t_vs = &t_EI
let &t_VS = &t_EI

" the default cursor visible/invisible codes include "\e[?c" sequences,
" which reset the cursor shape (preventing t_SI, t_SR, and t_EI from
" working)
let &t_ve = "\e[?25h"
let &t_vi = "\e[?25l"

" reset cursor shape when vim exits
autocmd VimLeave * call echoraw("\e[?c")

endif " &term =~ "linux"

Thank you,

Kyle Marek

Reply all
Reply to author
Forward
0 new messages