Monday, July 25, 2022

Re: Highlight character under cursor in visual mode

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

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/0853a25c-9dbc-a576-bd37-a54b6ad3f938%40gmail.com.

No comments: