Vim cursror is always set to the one of Windows Terminal #11776

Closed
opened 2026-01-31 02:57:05 +00:00 by claunia · 17 comments
Owner

Originally created by @jclsn on GitHub (Dec 11, 2020).

The cursor in Vim doesn't change and the solutions provided in issue 4335 don't work.

Environment

Windows build number: 10.0.18363.0
Windows Terminal version (if applicable):  1.4.3243.0
Vim: 8.2.2127

Steps to reproduce

Install Vim and switch from normal to insert mode. The cursor always stays the same. You can set the cursor in the Windows Terminal settings .json, but it will not change in Vim.

Expected behavior

The cursor should change when switching modes in Vim

Actual behavior

It doesn't change

Originally created by @jclsn on GitHub (Dec 11, 2020). The cursor in Vim doesn't change and the solutions provided in [issue 4335](https://github.com/microsoft/terminal/issues/4335) don't work. # Environment ```none Windows build number: 10.0.18363.0 Windows Terminal version (if applicable): 1.4.3243.0 Vim: 8.2.2127 ``` # Steps to reproduce Install Vim and switch from normal to insert mode. The cursor always stays the same. You can set the cursor in the Windows Terminal settings .json, but it will not change in Vim. # Expected behavior The cursor should change when switching modes in Vim # Actual behavior It doesn't change
claunia added the Resolution-Duplicate label 2026-01-31 02:57:05 +00:00
Author
Owner

@DHowett commented on GitHub (Dec 11, 2020):

WHAT VERSION OF VIM are you using. You didn't list "any other software", which is part of the template, so we can't even tell if you're using Windows vim or Linux vim in WSL.

@DHowett commented on GitHub (Dec 11, 2020): **WHAT VERSION OF VIM** are you using. You didn't list "any other software", which is part of the template, so we can't even tell if you're using Windows vim or Linux vim in WSL.
Author
Owner

@jclsn commented on GitHub (Dec 11, 2020):

I updated the issue

@jclsn commented on GitHub (Dec 11, 2020): I updated the issue
Author
Owner

@DHowett commented on GitHub (Dec 11, 2020):

Are you using windows vim.exe or vim inside wsl.

@DHowett commented on GitHub (Dec 11, 2020): Are you using windows vim.exe or vim inside wsl.
Author
Owner

@jclsn commented on GitHub (Dec 11, 2020):

I am using the Windows version, because I am working with a Windows-only compiler, but the behavior is the same for WSL2 in Windows Terminal. When I use WSL only the cursor is always a block and when I use Powershell only the cursor is a block in normal mode and an underscore in insert mode.

To be specific:

Powershell in Windows Terminal (normal & insert mode):
image

WSL in Windows Terminal (normal & insert mode):
image

For the pure Powershell I have made the block cursor the defaults setting in the Powershell settings, which results in a block for normal mode and an underscore for insert mode, which is acceptable. But then the Vim themes don't work well in Powershell, but they do in Windows Terminal...

Pure Powershell (normal mode):
image

Pure Powershell (insert mode):
image

Pure WSL (normal & insert mode):
image

@jclsn commented on GitHub (Dec 11, 2020): I am using the Windows version, because I am working with a Windows-only compiler, but the behavior is the same for WSL2 in Windows Terminal. When I use WSL only the cursor is always a block and when I use Powershell only the cursor is a block in normal mode and an underscore in insert mode. To be specific: Powershell in Windows Terminal (normal & insert mode): ![image](https://user-images.githubusercontent.com/19779511/101945160-14135a80-3bee-11eb-813b-d37dc65d9832.png) WSL in Windows Terminal (normal & insert mode): ![image](https://user-images.githubusercontent.com/19779511/101945203-27262a80-3bee-11eb-9d0d-43adae811faf.png) For the pure Powershell I have made the block cursor the defaults setting in the Powershell settings, which results in a block for normal mode and an underscore for insert mode, which is acceptable. But then the Vim themes don't work well in Powershell, but they do in Windows Terminal... Pure Powershell (normal mode): ![image](https://user-images.githubusercontent.com/19779511/101946092-e2e75a00-3bee-11eb-8b11-06d1ad4744cd.png) Pure Powershell (insert mode): ![image](https://user-images.githubusercontent.com/19779511/101945311-50df5180-3bee-11eb-846d-2db0ebf51ec5.png) Pure WSL (normal & insert mode): ![image](https://user-images.githubusercontent.com/19779511/101945386-6b192f80-3bee-11eb-943b-8fe64d5cd227.png)
Author
Owner

@OAguinagalde commented on GitHub (Jan 10, 2021):

Facing the same issue

@OAguinagalde commented on GitHub (Jan 10, 2021): Facing the same issue
Author
Owner

@sophec commented on GitHub (Jun 16, 2021):

I'm not sure that this is a WT issue. The shape of the cursor is configured in vim, and by default will not change when switching modes (that I am aware of). Additionally, make sure that your vim version includes the +cursorshape feature (:echo has('cursorshape') should print 1, and it should say +cursorshape in the output of vim --version). I use nvim (version v0.5.0-dev+16044ae-dirty) and vim (version 8.2) with the same .vimrc and both have no issue under WSL with the cursor changing from mode to mode. Try adding this to your .vimrc:

let &t_SI.="\e[5 q"
let &t_SR.="\e[4 q"
let &t_EI.="\e41 q"

For more info on this, see :h termcap-cursor-shape. I am unable to reproduce this issue, and by default vim will not change cursor shapes when changing modes (if you do vim -u NONE in PowerShell, you may see this behavior as well). It's likely that the default system-wide vimrc being used in PowerShell is setting this up for you.

Note: Neovim does by default change the cursor, and the options above will work, but are not the recommended way. In Neovim, see :h guicursor to change it.

@sophec commented on GitHub (Jun 16, 2021): I'm not sure that this is a WT issue. The shape of the cursor is configured in vim, and by default will not change when switching modes (that I am aware of). Additionally, make sure that your vim version includes the +cursorshape feature (`:echo has('cursorshape')` should print `1`, and it should say `+cursorshape` in the output of `vim --version`). I use nvim (version `v0.5.0-dev+16044ae-dirty`) and vim (version `8.2`) with the same .vimrc and both have no issue under WSL with the cursor changing from mode to mode. Try adding this to your .vimrc: ```vim let &t_SI.="\e[5 q" let &t_SR.="\e[4 q" let &t_EI.="\e41 q" ``` For more info on this, see `:h termcap-cursor-shape`. I am unable to reproduce this issue, and by default vim will not change cursor shapes when changing modes (if you do `vim -u NONE` in PowerShell, you may see this behavior as well). It's likely that the default system-wide vimrc being used in PowerShell is setting this up for you. Note: Neovim does by default change the cursor, and the options above will work, but are not the recommended way. In Neovim, see `:h guicursor` to change it.
Author
Owner

@lemonnuggets commented on GitHub (Jul 29, 2021):

    let &t_SI = "\<Esc>[6 q"
    let &t_SR = "\<Esc>[3 q"
    let &t_EI = "\<Esc>[2 q"

This is what I had to add to my .vimrc to make the cursor function as expected in WT.

@lemonnuggets commented on GitHub (Jul 29, 2021): ``` let &t_SI = "\<Esc>[6 q" let &t_SR = "\<Esc>[3 q" let &t_EI = "\<Esc>[2 q" ``` This is what I had to add to my .vimrc to make the cursor function as expected in WT.
Author
Owner

@aguevara commented on GitHub (Sep 27, 2021):

I see the same behavior on WT with Powershell 7. If it's not a problem with WT, then why does vim's cursor work as expected even in the windows console (cmd.exe and powershell.exe)? Would be great to see this fixed since I cannot use WT if vim doesn't work there just like it works everywhere else. Who would? Similar problem exists in WT when using Set-PSReadLine to vi. WT is the "only one" who requires a cursor change handler to be set via Set-PSReadLine. Everyone else "just works".

@aguevara commented on GitHub (Sep 27, 2021): I see the same behavior on WT with Powershell 7. If it's not a problem with WT, then why does vim's cursor work as expected even in the windows console (cmd.exe and powershell.exe)? Would be great to see this fixed since I cannot use WT if vim doesn't work there just like it works everywhere else. Who would? Similar problem exists in WT when using Set-PSReadLine to vi. WT is the "only one" who requires a cursor change handler to be set via Set-PSReadLine. Everyone else "just works".
Author
Owner

@zadjii-msft commented on GitHub (Sep 27, 2021):

I could've swore we had a dupe for this laying around.

I'm pretty sure apps that change the cursor size using the Win32 API won't have those changes mirrored to the Terminal. Apps that set the cursor shape with VT sequences should work just fine.

vim.exe is likely one of the former, because it predates the existence of any VT support in the Terminal.

vim in WSL is one of the later, because everything in WSL only uses VT to interact with the Terminal.

So if you're using Win32 vim.exe, you'll have to do something like what @‍willeccles mentioned, as a workaround while we figure out a way to communicate cursor height to the Terminal (since there's not an existing VT sequences for "set the cursor height", only "set the cursor shape").


possibly related:

Actually after re-reading that I think this is /dup #7382

@zadjii-msft commented on GitHub (Sep 27, 2021): I could've swore we had a dupe for this laying around. I'm pretty sure apps that change the cursor size using the Win32 API won't have those changes mirrored to the Terminal. Apps that set the cursor shape with VT sequences should work just fine. `vim.exe` is likely one of the former, because it predates the existence of any VT support in the Terminal. `vim` in WSL is one of the later, because everything in WSL only uses VT to interact with the Terminal. So if you're using Win32 `vim.exe`, you'll have to do something like what **@&zwj;willeccles** mentioned, as a workaround while we figure out a way to communicate cursor height to the Terminal (since there's not an existing VT sequences for "set the cursor height", only "set the cursor shape"). <hr> possibly related: * #4106 * #1604 * #7382 Actually after re-reading that I think this _is_ /dup #7382
Author
Owner

@ghost commented on GitHub (Sep 27, 2021):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Sep 27, 2021): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@aguevara commented on GitHub (Sep 27, 2021):

Vimscripts provided by @willeccles and @lemonnuggets work poorly on pwsh in WT. It's also not clear why their scripts differ from each other's. Their examples also break the already-working cursor on the regular windows console when running vim from cmd.exe or pwsh.exe. Powershell's Set-PSReadLineOption also doesn't work the same way between windows console and WT, and when used in combination with the vimscripts mentioned, there more problems ensue. In windows console, it's sufficient to call Set-PSReadLineOption -EditMode vi -ViModeIndicator Cursor to get a default cursor-changing behavior in powershell.exe and pwsh.exe. But the same powershell profile doesn't work in WT, so a custom profile / change handler is required for WT. For WT, I'm doing Set-PSReadlineOption -EditMode v -BellStyle None -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange.

Cursor guidance for vim on different terminals can be found here

Would it be possible to update that listing with similar guidance for WT that has actually been tested with the different shells that WT supports, and, if necessary, when used in combination with Set-PSReadLineOption? At least in the meantime until the WT team has figured out if WT can be "fixed" so that vim works consistently on WT and the windows console?

@aguevara commented on GitHub (Sep 27, 2021): Vimscripts provided by @willeccles and @lemonnuggets work poorly on pwsh in WT. It's also not clear why their scripts differ from each other's. Their examples also break the already-working cursor on the regular windows console when running vim from cmd.exe or pwsh.exe. Powershell's Set-PSReadLineOption also doesn't work the same way between windows console and WT, and when used in combination with the vimscripts mentioned, there more problems ensue. In windows console, it's sufficient to call `Set-PSReadLineOption -EditMode vi -ViModeIndicator Cursor` to get a default cursor-changing behavior in powershell.exe and pwsh.exe. But the same powershell profile doesn't work in WT, so a custom profile / change handler is required for WT. For WT, I'm doing `Set-PSReadlineOption -EditMode v -BellStyle None -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange`. Cursor guidance for vim on different terminals can be found [here](https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes) Would it be possible to update that listing with similar guidance for WT that has actually been tested with the different shells that WT supports, and, if necessary, when used in combination with Set-PSReadLineOption? At least in the meantime until the WT team has figured out if WT can be "fixed" so that vim works consistently on WT and the windows console?
Author
Owner

@sophec commented on GitHub (Sep 28, 2021):

The escape sequences will not work in cmd.exe or pwsh.exe if they do not support them. Windows Terminal seems to, and I've had no issue using that setup for years now on numerous terminals (including WT). The other user's script only differs from mine in that it's harder to read and achieves slightly different cursor configurations. I will note that I have used vim.exe for a total of maybe an hour in my life, and these days I only use vim through WSL on WT. As far as I'm aware, WT should have no issues with these escape sequences.

@sophec commented on GitHub (Sep 28, 2021): The escape sequences will not work in cmd.exe or pwsh.exe if they do not support them. Windows Terminal seems to, and I've had no issue using that setup for years now on numerous terminals (including WT). The other user's script only differs from mine in that it's harder to read and achieves slightly different cursor configurations. I will note that I have used vim.exe for a total of maybe an hour in my life, and these days I only use vim through WSL on WT. As far as I'm aware, WT should have no issues with these escape sequences.
Author
Owner

@aguevara commented on GitHub (Sep 28, 2021):

As I said, for me they aren't working in vim in pwsh in WT. As you said, you are using it in WSL, I haven't tried there. I'm talking vim.exe in pwsh in WT on Win10.

@aguevara commented on GitHub (Sep 28, 2021): As I said, for me they aren't working in vim in pwsh in WT. As you said, you are using it in WSL, I haven't tried there. I'm talking vim.exe in pwsh in WT on Win10.
Author
Owner

@sophec commented on GitHub (Sep 28, 2021):

@zadjii-msft's comment implies to me that it should work, though it's possible that updates to WT have broken it as well. Also, make sure you have +cursorshape in the output of vim --version, as this is all moot if it's compiled without support for it.

@sophec commented on GitHub (Sep 28, 2021): @zadjii-msft's comment implies to me that it should work, though it's possible that updates to WT have broken it as well. Also, make sure you have `+cursorshape` in the output of `vim --version`, as this is all moot if it's compiled without support for it.
Author
Owner

@aguevara commented on GitHub (Sep 28, 2021):

Yes, I am compiled with +cursorshape. It doesn't sound like he's tried this with windows vim.exe in pwsh on WT. Because it's not working :)

@aguevara commented on GitHub (Sep 28, 2021): Yes, I am compiled with `+cursorshape`. It doesn't sound like he's tried this with windows vim.exe in pwsh on WT. Because it's not working :)
Author
Owner

@phortonssf commented on GitHub (Oct 19, 2021):

Side subject here, anyone knows the terminal escape sequence for the openBox cursor? That would make me very happy and be an easy solution. I also have the same issue as well with neovim .05 and .06. Replicated the issue in Windows terminal with wsl and ubuntu:focal in docker. I tried the below with other cursor shapes as well same thing. My zshrc and init.vim are empty. I am pretty sure it's an issue with NEOVIM in my case.

NEOVIM 3681

https://share.getcloudapp.com/mXuPEo5n

@phortonssf commented on GitHub (Oct 19, 2021): Side subject here, anyone knows the terminal escape sequence for the openBox cursor? That would make me very happy and be an easy solution. I also have the same issue as well with neovim .05 and .06. Replicated the issue in Windows terminal with wsl and ubuntu:focal in docker. I tried the below with other cursor shapes as well same thing. My zshrc and init.vim are empty. I am pretty sure it's an issue with NEOVIM in my case. [NEOVIM 3681](https://github.com/neovim/neovim/issues/3681) https://share.getcloudapp.com/mXuPEo5n
Author
Owner

@j4james commented on GitHub (Oct 19, 2021):

Side subject here, anyone knows the terminal escape sequence for the openBox cursor?

There's not a standard sequence for that, but there was a discussion in issue #7382 about potentially extending the DECSCUSR sequences with other shapes, in the same way that nosh has done (see here). If that ever happens, the openBox cursor would be enabled with DECSCUSR 7 or 8 (depending on whether you want it blinking or not).

@j4james commented on GitHub (Oct 19, 2021): > Side subject here, anyone knows the terminal escape sequence for the openBox cursor? There's not a standard sequence for that, but there was a discussion in issue #7382 about potentially extending the `DECSCUSR` sequences with other shapes, in the same way that _nosh_ has done (see [here](http://jdebp.uk./Softwares/nosh/guide/commands/console-control-sequence.xml)). If that ever happens, the openBox cursor would be enabled with `DECSCUSR` 7 or 8 (depending on whether you want it blinking or not).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#11776