No cursor after exiting vim #14637

Open
opened 2026-01-31 04:15:34 +00:00 by claunia · 17 comments
Owner

Originally created by @polluks on GitHub (Jul 22, 2021).

Windows Terminal version (or Windows build number)

1.8.1521.0

Other Software

vim 7.4.576 (via SSH inside WSL)

        linux-vdso.so.1 (0x00007ffffd7f6000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f151d9c1000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f151d797000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f151d572000)
        libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f151d369000)
        libgpm.so.2 => /usr/lib/x86_64-linux-gnu/libgpm.so.2 (0x00007f151d163000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f151cf5f000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f151cbb4000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f151c946000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f151e0ef000)
        libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f151c741000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f151c524000)

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.

Originally created by @polluks on GitHub (Jul 22, 2021). ### Windows Terminal version (or Windows build number) 1.8.1521.0 ### Other Software vim 7.4.576 (via SSH inside WSL) ```` linux-vdso.so.1 (0x00007ffffd7f6000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f151d9c1000) libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f151d797000) libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f151d572000) libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f151d369000) libgpm.so.2 => /usr/lib/x86_64-linux-gnu/libgpm.so.2 (0x00007f151d163000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f151cf5f000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f151cbb4000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f151c946000) /lib64/ld-linux-x86-64.so.2 (0x00007f151e0ef000) libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f151c741000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f151c524000) ```` ### 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.
Author
Owner

@DHowett commented on GitHub (Jul 22, 2021):

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 commented on GitHub (Jul 22, 2021): 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.
Author
Owner

@polluks commented on GitHub (Jul 22, 2021):

@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.

@polluks commented on GitHub (Jul 22, 2021): @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.
Author
Owner

@Nosamdaman commented on GitHub (Jul 26, 2021):

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.

@Nosamdaman commented on GitHub (Jul 26, 2021): 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.
Author
Owner

@polluks commented on GitHub (Aug 2, 2021):

Fun fact: The cursor is off, I start vim again and see the cursor!
I leave vim and the cursor is off again...

@polluks commented on GitHub (Aug 2, 2021): Fun fact: The cursor is off, I start vim again and see the cursor! I leave vim and the cursor is off again...
Author
Owner

@j4james commented on GitHub (Aug 3, 2021):

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 commented on GitHub (Aug 3, 2021): 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 <kbd>Ctrl</kbd>+<kbd>[</kbd>). ``` 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`.
Author
Owner

@polluks commented on GitHub (Aug 9, 2021):

@j4james It works, but you are just fixing the symptoms.

@polluks commented on GitHub (Aug 9, 2021): @j4james It works, but you are just fixing the symptoms.
Author
Owner

@j4james commented on GitHub (Aug 9, 2021):

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.

@j4james commented on GitHub (Aug 9, 2021): 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.
Author
Owner

@polluks commented on GitHub (Aug 10, 2021):

Well, at least Xterm.js supports DECSCUSR
e746cd55dd/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/

@polluks commented on GitHub (Aug 10, 2021): 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/
Author
Owner

@j4james commented on GitHub (Aug 10, 2021):

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.
e746cd55dd/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.

@j4james commented on GitHub (Aug 10, 2021): > 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_.
Author
Owner

@polluks commented on GitHub (Aug 12, 2021):

Just for the record https://invisible-island.net/ncurses/ncurses.faq.html#emacs_cvvis

@polluks commented on GitHub (Aug 12, 2021): Just for the record https://invisible-island.net/ncurses/ncurses.faq.html#emacs_cvvis
Author
Owner

@TrT-TOT commented on GitHub (Oct 11, 2021):

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...

@TrT-TOT commented on GitHub (Oct 11, 2021): > 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...
Author
Owner

@tjy137 commented on GitHub (Oct 26, 2021):

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.

@tjy137 commented on GitHub (Oct 26, 2021): 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`): ``` vim " 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.
Author
Owner

@zadjii-msft commented on GitHub (Feb 23, 2022):

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 the cnorm 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

@zadjii-msft commented on GitHub (Feb 23, 2022): 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 the `cnorm` 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
Author
Owner

@angelog0 commented on GitHub (Aug 20, 2022):

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

@angelog0 commented on GitHub (Aug 20, 2022): 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
Author
Owner

@gtirloni commented on GitHub (Mar 8, 2024):

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

@gtirloni commented on GitHub (Mar 8, 2024): 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
Author
Owner

@dkaszews commented on GitHub (Apr 9, 2025):

I can see similar issue with Neovim 0.10.4. Cursor completely disappears as if hidden by \e[?25l, but never reappears even after reentering Neovim. Could not find any way to fix it other than closing terminal tab, which is quite annoying.

@dkaszews commented on GitHub (Apr 9, 2025): I can see similar issue with Neovim 0.10.4. Cursor completely disappears as if hidden by `\e[?25l`, but never reappears even after reentering Neovim. Could not find any way to fix it other than closing terminal tab, which is quite annoying.
Author
Owner

@polluks commented on GitHub (Jun 25, 2025):

I can see similar issue with Neovim 0.10.4. Cursor completely disappears as if hidden by \e[?25l, but never reappears even after reentering Neovim. Could not find any way to fix it other than closing terminal tab, which is quite annoying.

What about /usr/bin/reset?

@polluks commented on GitHub (Jun 25, 2025): > I can see similar issue with Neovim 0.10.4. Cursor completely disappears as if hidden by `\e[?25l`, but never reappears even after reentering Neovim. Could not find any way to fix it other than closing terminal tab, which is quite annoying. What about /usr/bin/reset?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14637