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 Cursor shape stays underscore. Not able to change it #68

Closed
bitcrazed opened this issue Feb 16, 2018 · 40 comments
Closed

Vim Cursor shape stays underscore. Not able to change it #68

bitcrazed opened this issue Feb 16, 2018 · 40 comments
Assignees
Labels
Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Conhost For issues in the Console codebase Resolution-Fix-Available It's available in an Insiders build or a release
Milestone

Comments

@bitcrazed
Copy link
Contributor

From @ponegan on January 9, 2018 6:40

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.16299.125]

  • What you're doing and what's happening / What's wrong / what should be happening instead:
    I'm using xterm-256color.
    I had been tried to change the shape of my vim cursor. I tried lots of different configuration for cursor shape (to be block) but none of them works as I put them in my .vimrc.

For example I tried some of these:
http://vim.wikia.com/wiki/Configuring_the_cursor

In the terminal I was able to change the shape of cursor to block by selecting 'large' in property as @zadjii-msft suggested in #1253. But the same trick won't work for vim. Well.... it will work at the moment I set it to 'large'. But it will reset back to underscore every time I open another file.

As this:
image

Anyone got a good approach on this cursor configuration?

Copied from original issue: microsoft/WSL#2821

@bitcrazed
Copy link
Contributor Author

From @parkovski on January 10, 2018 21:27

I don't think this is possible right now - the console needs to understand a cursor escape, like ^[[n q with n from 0-6, which it doesn't. The only way I know to change it right now is with console APIs that are not available within WSL. Hopefully this functionality will get implemented soon.

Edit - there may be a hacky way to do this right now. You can write a small Windows C program that calls SetConsoleCursorInfo, and set up vim's cursor sizing commands to run that program. I think that would work, but no guarantees.

@p-groarke
Copy link

Any updates on this? It is required for good out-of-the-box experience with vim/nvim.

@zadjii-msft
Copy link
Member

Oh yea! I added support for cursor shapes, colors for RS5. If vim's using them to set the shape, then they should work. It's on it's way to Insiders now :)

@zadjii-msft zadjii-msft added Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Conhost For issues in the Console codebase Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed console labels Mar 20, 2018
@zadjii-msft zadjii-msft added this to the RS5 milestone Mar 20, 2018
@zadjii-msft zadjii-msft self-assigned this Mar 20, 2018
@p-groarke
Copy link

Wow the command prompt team keeps delivering time and time again. What a time to be alive! Thanks for all the great work.

@zadjii-msft
Copy link
Member

That's because we're the best :P

As a teaser, here's a pic of a vertical bar cursor in a pleasing cyan:
image

Of course, there are other shapes too if you so choose. That's just my default.

@bitcrazed
Copy link
Contributor Author

@p-groarke Thanks for the kind words, but please stop being nice to our dev's - it makes them all happy and distracts them from their long list of bugs & features.

Back to your keyboard @zadjii-msft or I'll have to put you on notice again ;)
backtowork

@p-groarke
Copy link

lol!

@ghost
Copy link

ghost commented Aug 31, 2018

Any update? really need vertical bar and block cursor to work with vim, I can't distinguish I'm in normal mode or insert mode. @zadjii-msft and give me your $PS1 :D

@zadjii-msft
Copy link
Member

@tuyenpm9 that's no $PS1, that's a %PROMPT% setting in CMD:
https://github.com/zadjii/keep/blob/master/bin/reprompt.cmd#L33

Also, I'm certain support for this is in Insider's (at the very least). How are you setting your cursor shape in vim?

I know that this method works at the very least: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes#For_Terminal_on_macOS

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

@ghost
Copy link

ghost commented Sep 5, 2018

I use default cursor shape in vim. I don't know what kind of terminal when running ../system32/bash.exe but setting those in vim doesn't work, I tried others too, seem terminal forced cursor shape despite of applications.

Non-related question: I got this error when trying to run cmd> reprompt - bin is in PATH

'em' is not recognized as an internal or external command,
operable program or batch file.

@zadjii-msft
Copy link
Member

@tuyenpm9 What build of Windows are you running?

The "terminal" you get when you run a commandline application on Windows is conhost.exe. It's definitely not listed on that page, but I can assure you that adding those lines to your .vimrc should work on insider's builds: (the cursor is on line 5)

Normal Mode:
image

Insert Mode:
image


Are you sure that you copied the entire file? 'em' sounds like you're missing a @r or possibly a r from the start of a @rem or rem. Can you paste the output of reprompt with the @echo off at the top commented out?

@parkovski
Copy link

parkovski commented Sep 5, 2018

Windows or Linux vim? I’ve found those cursor codes work in Linux vim (WSL) but not Windows. Not sure why. Neovim on Windows does support it but you have to use &guicursor.

@ghost
Copy link

ghost commented Sep 6, 2018

@parkovski : This is terminal vim.

@zadjii-msft : I use version 1709 build 16299.611, probably not insider version.

I clone keep repo and add /bin to PATH and try reprompt on cmd, not sure why but reprompt.cmd is original from your repo.

@zadjii-msft
Copy link
Member

@tuyenpm9 I don't recall when exactly I added support for cursor shapes, but I believe it was 1803. It was definitely after 1709. I'd try upgrading, that'll probably light this up for you.


I opened zadjii/keep#1 to track your issues with reprompt

@parkovski
Copy link

@tuyenpm9 - Should have been clearer, sorry. All non-terminal versions (gvim) support this via &guicursor. Terminal vim on Linux supports this via &t_SI, etc. Neovim, terminal or not, regardless of platform, supports &guicursor. Windows vim in the console (vim.exe) to my knowledge does not have support for cursor shapes. Setting &t_SI does something in vim.exe but not the right thing.

Anyways, I don't think my question is relevant anymore due to your build number.

@kariem-ali
Copy link

It would help to know which Windows build this was fixed in. I am on Windows 10 version 1803 build number 17134.320 and I still have the issue.

@zadjii-msft
Copy link
Member

That might by my mistake - looks like it actually wasn't merged in finally until after the cutoff for 1803, so it's not actually in 1803. I can't be sure which is the actual build number with it enabled, but it's definitely after 17134.

@kariem-ali
Copy link

I can confirm that this fix was included in Windows 10 version 1809 (Build 17763.194).

@miniksa miniksa removed the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Dec 13, 2018
@will
Copy link

will commented Feb 5, 2019

This is I suppose tangental to the issue, but I really want the cursor to change in vim. I don’t know how to get 1809. I'm on 1803 (17134.556), and there is no update available. I tried doing that insiders program, but after doing the link my account go get started, it just does a little spin, then my account never gets added. Maybe because it's an azure vm and/or the account is an alias(at)microsoft.com there is some restriction? (sorry I have no real idea how to use windows, which is why I'm clinging to vim and wsl as much as I can ;) )

@simlei
Copy link

simlei commented Oct 7, 2019

I can not observe this issue is fixed. I am on Windows 10 18362, Terminal v. 0.5.2762 , PS Core 7 (Preview)
When I start vim.exe there (Terminal Vim), The cursor does not change. Am I missing something?

Thanks for the great work though!

@parkovski
Copy link

parkovski commented Oct 8, 2019

I've never been able to get the cursor change working in vim.exe and I don't know why. I mostly use neovim, and it does work there, so I think this is a vim issue now.

Edit - just experimented a bit, it sort of works this way, but the screen gets glitchy for me:

let &t_SI="\<CSI>5 q"
let &t_EI="\<CSI>1 q"

@ragvri
Copy link

ragvri commented Dec 21, 2019

I am on the latest version of windows (1909). I tried all the methods mentioned above on vim in WSL. Nothing works for me :/

@sleep2death
Copy link

I am on the latest version of windows (1909). I tried all the methods mentioned above on vim in WSL. Nothing works for me :/

hi @ragvri, try install the latest "windows terminal", and run your wsl in it.

@travisl09
Copy link

Got block/bar cursor working in powershell, cmd, and wsl with :

if &term == 'win32'
        let &t_ti.=" \e[1 q"
        let &t_SI.=" \e[5 q-- INSERT --"
        let &t_EI.=" \e[1 q"
        let &t_te.=" \e[0 q"
else
        let &t_ti.="\e[1 q"
        let &t_SI.="\e[5 q"
        let &t_EI.="\e[1 q"
        let &t_te.="\e[0 q"
endif

Note spaces before the control sequence in the win32 terminal configuration.
A few quirks but all in all much better than the cursor not indicating the current mode

Microsoft Windows [Version 10.0.18362.657] 1903
VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:26:56)

WSL - Ubuntu 18.04.4 LTS
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 17:31:41)

@hummeleBop
Copy link

if &term == 'win32'
        let &t_ti.=" \e[1 q"
        let &t_SI.=" \e[5 q-- INSERT --"
        let &t_EI.=" \e[1 q"
        let &t_te.=" \e[0 q"
else
        let &t_ti.="\e[1 q"
        let &t_SI.="\e[5 q"
        let &t_EI.="\e[1 q"
        let &t_te.="\e[0 q"
endif

Thanks for this, but somehow, it doesn't work when set termguicolors is enabled

@hulucc
Copy link

hulucc commented May 21, 2020

Nothing is work for windows terminal vim.

@j-oshb
Copy link

j-oshb commented Jun 2, 2020

For what it's worth none of the above configurations are working for me.

#68 (comment) is the only configuration that changes the shape at all - it changes the cursor to a block when vim starts, but then it won't change again on any mode changes.

Windows Terminal Version: 1.0.1401.0
Microsoft Windows Version 10.0.18363.836
VIM - Vi IMproved 8.0
WSL Alpine

EDIT: What this means is that setting &t_te has an effect (I can set it to any cursor shape), but setting any of the others (&t_ti, &t_SI, &t_EI) doesn't.

EDIT 2: Ok, this wasn't a windows terminal issue. If it helps anyone, there were two things that stopped it working:

  1. Using byobu.
  2. This line in vimrc: set term=xterm-256color.

@mbowman34
Copy link

mbowman34 commented Jul 14, 2020

@tuyenpm9 that's no $PS1, that's a %PROMPT% setting in CMD:
https://github.com/zadjii/keep/blob/master/bin/reprompt.cmd#L33

Also, I'm certain support for this is in Insider's (at the very least). How are you setting your cursor shape in vim?

I know that this method works at the very least: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes#For_Terminal_on_macOS

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

Also can add
autocmd VimLeave * silent !echo -ne "\x1b[\x35 q"
or any value x31-x35 to set the cursor back to your default after exiting vim

@gustaphe
Copy link

gustaphe commented Aug 7, 2020

I thought I'd add to this because this turns up in the google results, and I've tried every combination.

What finally worked for me was

let &t_SI="\<CSI>5\ q"
let &t_SR="\<CSI>7\ q"
let &t_EI="\<CSI>2\ q"

There's still an issue where the single character replace mode glitches out, but this fixed a lot of the visual bugs I had with other versions of this.

@mechatroner
Copy link

There is also a psychological hack: at first, the underscore cursor looks very annoying and unnatural, but after a month of usage you will be absolutely comfortable with it and even won't notice a switch between the underscore cursor and the standard block cursor when working in other environments. At least this is what happened to me.

@mbowman34
Copy link

There is also a psychological hack: at first, the underscore cursor looks very annoying and unnatural, but after a month of usage you will be absolutely comfortable with it and even won't notice a switch between the underscore cursor and the standard block cursor when working in other environments. At least this is what happened to me.

Sure but not being able to distinguish between insert and command mode is annoying

@gustaphe
Copy link

gustaphe commented Aug 7, 2020

In my case it defaulted to either vertical bar or blinking block, both of which are unacceptable.

@mbowman34
Copy link

In my case it defaulted to either vertical bar or blinking block, both of which are unacceptable.

The default cursor for the terminal is easily configurable in settings. Just change the cursorShape for the profile you're using.

@oscarhermoso
Copy link

Got block/bar cursor working in powershell, cmd, and wsl with :

if &term == 'win32'
        let &t_ti.=" \e[1 q"
        let &t_SI.=" \e[5 q-- INSERT --"
        let &t_EI.=" \e[1 q"
        let &t_te.=" \e[0 q"
else
        let &t_ti.="\e[1 q"
        let &t_SI.="\e[5 q"
        let &t_EI.="\e[1 q"
        let &t_te.="\e[0 q"
endif

Note spaces before the control sequence in the win32 terminal configuration.
A few quirks but all in all much better than the cursor not indicating the current mode

Microsoft Windows [Version 10.0.18362.657] 1903
VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:26:56)

WSL - Ubuntu 18.04.4 LTS
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 17:31:41)

This saved the day for me, but there was a quirk with leaving Insert mode and keeping a vertical bar instead of a block cursor for about a second. Following this advice, adding set noesckeys to my vimrc solved this for me.

@MikeClark512
Copy link

MikeClark512 commented Mar 14, 2021

travisl09 wrote:
Got block/bar cursor working in powershell, cmd, and wsl [ ... ]

oscarhermoso wrote:
This saved the day for me, but there was a quirk with leaving Insert mode and keeping a vertical bar instead of a block cursor for about a second.

Yes, I also noticed this glitch -- when Esc-ing out of insert mode back to normal mode.

Following this advice, adding set noesckeys to my vimrc solved this for me.

Big downside to set noesckeys: in terminals that use ^[ to transmit control keys (e.g. Linux/WSL), this will badly break arrow keys (and keys: home, end, pgdn, etc.) while in insert mode. If you don't use those keys, or your terminal doesn't use ^[ as a control code, then noesckeys is ideal. But, I those keys a lot in WSL, so I needed something else.

What worked better for me was to use the ttimeoutlen suggestion (also from the link you found, thanks!):

set ttimeoutlen=50

I suggest trying values of 250, 50, or 5 to balance* your computer/network speed with your preference for responsiveness.

*To explain a bit more about this balancing act: setting lower values will make pressing escape look and feel more responsive, but on slow computers or slow networks, setting the value too low may interfere with your ability to use control keys (like arrow keys) while in non-normal modes in vim. If you're feeling conservative, just pick something like 250 and deal with the small big of sluggishness. If you're feeling adventurous, keep setting the value lower and lower until it breaks, then back off. :)

@yutotakano
Copy link

The given solutions work great, but unfortunately introduces major visual glitches when noshowmode is set. I have no idea why, as it seems relatively unrelated, but it's definitely the culprit.

@gustaphe
Copy link

gustaphe commented Jun 23, 2022

Update: My strange solution is broken/not necessary now (don't know since when). The following works when sourced, but not when autoloaded as vimrc. I have no idea what's going on.

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

let &t_ti=" \e[S \e[2 q"
let &t_te=" \e[E \e[1 q"

(I still see the visual bug for r)

@hulucc
Copy link

hulucc commented Jul 14, 2022

By win32 vim.exe, accroding to #10827 (comment), actually you should never set any of t_SI things, because vim.exe never supported this when `set term=win32'. It's not function as expect, and bring a lot of glitch.

So the workaround for win32 vim is to build a c library do the job.

#include "stdio.h"

__declspec(dllexport) void setCursorType(int type) {
    printf("�[%d q", type);
}
  let g:vimxdll="<path-to-libcursor.dll>"
  au InsertEnter * :call libcall(g:vimxdll, "setCursorType", 5)
  au InsertLeave * :call libcall(g:vimxdll, "setCursorType", 1)
  au VimLeave * :call libcall(g:vimxdll, "setCursorType", 1)
  nnoremap <silent> r :call libcall(g:vimxdll, "setCursorType", 3)<cr>:au TextChanged,CursorMoved * ++once :call libcall(g:vimxdll, "setCursorType", 1)<cr>r

@gustaphe
Copy link

gustaphe commented Aug 9, 2022

So the workaround for win32 vim is to build a c library do the job.

I'd be happy to use this if it worked, but I can't seem to get anything but E364 on Windows. If you have any time to help me debug this maybe we can take the discussion here.

Nvm, that works perfectly, I just had to revert some changes I had to make to make it work on my development computer ...

@gustaphe
Copy link

I turned @hulucc's comment into a plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Conhost For issues in the Console codebase Resolution-Fix-Available It's available in an Insiders build or a release
Projects
None yet
Development

No branches or pull requests