Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jclsn opened this issue Dec 11, 2020 · 17 comments
Closed

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

jclsn opened this issue Dec 11, 2020 · 17 comments
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@jclsn
Copy link

jclsn commented 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

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Dec 11, 2020
@DHowett
Copy link
Member

DHowett commented 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 DHowett added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 11, 2020
@jclsn
Copy link
Author

jclsn commented Dec 11, 2020

I updated the issue

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Dec 11, 2020
@DHowett
Copy link
Member

DHowett commented Dec 11, 2020

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

@DHowett DHowett added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Dec 11, 2020
@jclsn
Copy link
Author

jclsn commented 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

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Dec 11, 2020
@OAguinagalde
Copy link

Facing the same issue

@willeccles
Copy link

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

@lemonnuggets
Copy link

    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.

@aguevara
Copy link

aguevara commented 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".

@zadjii-msft
Copy link
Member

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

@ghost
Copy link

ghost commented 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 ghost closed this as completed Sep 27, 2021
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements Needs-Attention The core contributors need to come back around and look at this ASAP. labels Sep 27, 2021
@aguevara
Copy link

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?

@willeccles
Copy link

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.

@aguevara
Copy link

aguevara commented Sep 27, 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.

@willeccles
Copy link

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

@aguevara
Copy link

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 :)

@phortonssf
Copy link

phortonssf commented 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

@j4james
Copy link
Collaborator

j4james commented 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).

jfishe added a commit to jfishe/vimfiles that referenced this issue Jul 25, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

9 participants