Open polluks opened 3 years ago
Looks like vim never restores the cursor blink status. This "regressed" due to the fix for #10543. Terminal used to ignore the request for a non-blinking cursor. Now it respects it, but vim never turns blinking back on.
There may also be an issue where we let them turn off blinking while the cursor is off.
@DHowett In November vim's 30th anniversary takes place. I suppose it's pretty stable.
Indeed, the issue depends on the cursor state.
Maybe it's related to this message: E72: Close error on swap file
. In VS Code's xterm.js it works.
It's worth noting that I'm seeing a similar issue with tig
. For both vim
and tig
, if the cursor stops blinking once I exit the application.
Fun fact: The cursor is off, I start vim again and see the cursor! I leave vim and the cursor is off again...
In the case of vim, you can get it to reset the cursor on exit by tweaking the t_ti
and t_te
options. For example, I have these lines in my .vimrc
file (note that ^[
is Ctrl+[).
set t_ti=^[[1049h
set t_te=^[[1049l^[[0\ q
On startup that switches to the alt buffer (CSI 1049h
), and on exit it switches back to the main buffer (CSI 1049l
), and resets the cursor (CSI 0 q
). I don't know if this is the best solution, but it works for me.
It's worth noting that I'm seeing a similar issue with
tig
.
In the case of tig
, the current behaviour is also "by design". They're essentially asking for the cursor blinking to be disabled on shutdown. They're executing the cursor_normal
terminfo entry, which for xterm-256color is \E[?12l\E[?25h
(i.e. cursor blink off and visibility on). You'll get the same result in XTerm. I don't know if there's a way to work around that, but you should probably raise the issue with tig
.
@j4james It works, but you are just fixing the symptoms.
Well if you want to fix the root cause then you'll probably need to take this up with vim. They're the ones that are turning the blinking off. I don't think it's anything specific to Windows Terminal, because I've seen the exact same behaviour in several other terminals, including XTerm , Rxvt, and Alacritty. The only terminals I've seen that weren't affected were those that simply don't support the cursor blinking mode, so they're only "working" accidentally.
Well, at least Xterm.js supports DECSCUSR https://github.com/xtermjs/xterm.js/blob/e746cd55ddafb9120e3f00cf00e4360d14a531a4/src/common/InputHandler.ts#L176 BTW there are users who use real blinking hardware https://www.reddit.com/r/commandline/comments/onagx8/adapt_vim_syntax_highlight_to_vt100/
Well, at least Xterm.js supports DECSCUSR
Yeah but vim is using private mode 12 to disable the cursor blinking, and Xterm.js doesn't appear to support that. https://github.com/xtermjs/xterm.js/blob/e746cd55ddafb9120e3f00cf00e4360d14a531a4/src/common/InputHandler.ts#L1948-L1950
Technically I suspect it's just using the cursor_normal
terminfo entry, the same as tig, and as I pointed out above, that disables mode 12 and enables mode 25 for xterm-256color.
Just for the record https://invisible-island.net/ncurses/ncurses.faq.html#emacs_cvvis
Well if you want to fix the root cause then you'll probably need to take this up with vim. They're the ones that are turning the blinking off. I don't think it's anything specific to Windows Terminal, because I've seen the exact same behaviour in several other terminals, including XTerm , Rxvt, and Alacritty. The only terminals I've seen that weren't affected were those that simply don't support the cursor blinking mode, so they're only "working" accidentally.
I use Xshell previously and the cursor blinks properly before and after i use vim. So I hope if someone could find a way to solve the problem...
Since this issue has been moved to the backlog and we could wait a while before an official fix comes out, I worked out a hacky solution for vim.
Here is how it works (lines to be put in .vimrc
):
" set cursor to be a solid box in normal mode
let &t_EI .= "\<Esc>[2 q"
" set cursor to be a blinking box in replace mode
let &t_SR .= "\<Esc>[1 q"
" set cursor to replace mode when leaving buffer in all windows
" revert cursor back to normal mode when entering buffer
autocmd BufEnter * execute 'silent !echo -ne "' . &t_EI . '"'
autocmd BufWinLeave * execute 'silent !echo -ne "' . &t_SR . '"'
The idea here is that the terminal will take the last cursor style in vim before exit. So I set a blinking cursor for the replace mode, and use autocmd
to start that mode when the buffer is exited on all windows. In order to keep the cursor solid after switching to another file without exiting to the terminal, I also start the normal mode with autocmd
when entering a buffer.
This is not meant to be perfect. Let me know if you find any problem with this, or if you have better solutions.
From @j4james in #12372
I think I know what's happening now. It looks like Mintty ignores the blinking escape sequence (private mode 12) if you've set your default cursor preference to be blinking, so that's why it appears to be working. Emacs is still requesting that the cursor stop blinking, but Mintty is simply ignoring that request.
BTW, after I quit Emacs (and cursor stops blinking), restarting Emacs the cursor returns to blinking in Emacs; exiting one more time, it returns to stop blinking...
That is exactly what I would expect. They're likely using the
cvvis
terminfo capability on startup (which enables cursor blinking), and thecnorm
capability on shutdown (which disables blinking).The bottom line is that this is a duplicate of #10754 and is really an Emacs problem. You can probably work around it by editing your terminfo if you don't ever want applications to stop your cursor blinking.
The mintty approach sure is an interesting one, but probably not the most broadly compatible experience
For completeness (see #12372), I just discovered that MinTTY people has enabled by default the MinTTY option
SuppressDEC=12
See https://github.com/mintty/mintty/wiki/Tips#blinking-cursor-reset
This is not exclusive to vim. Running top
also causes the cursor to stop blinking.
As much as I agree the issue is with the apps themselves and Microsoft Terminal is doing the right thing here, maybe an option to ignore that request like it was traditionally done would be nice.
Terminal 1.12.10983.0 Ubuntu 22.04.4 (Jammy) Vim 8.2 procps-ng 3.3.17
Windows Terminal version (or Windows build number)
1.8.1521.0
Other Software
vim 7.4.576 (via SSH inside WSL)
Steps to reproduce
A few times start vim, switch the window and wait...
Expected Behavior
Everytime a flashing cursor after switching back.
Actual Behavior
Sometimes the cursor disappears, reset(1) helps.