Terminal: Vim Cursor shape stays underscore. Not able to change it

Created on 16 Feb 2018  路  33Comments  路  Source: microsoft/terminal

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

Issue-Feature Product-Conhost Resolution-Fix-Available

Most helpful comment

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

All 33 comments

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

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

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

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

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.

@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

lol!

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

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

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.

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

Windows or Linux vim? I鈥檝e 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.

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

@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

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

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.

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.

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

This is I suppose tangental to the issue, but I really want the cursor to change in vim. I don鈥檛 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 ;) )

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!

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"

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

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.

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)

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

Nothing is work for windows terminal vim.

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

~https://github.com/microsoft/terminal/issues/68#issuecomment-621891237 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.
1) This line in vimrc: set term=xterm-256color.

@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

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.

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.

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DieselMeister picture DieselMeister  路  3Comments

TayYuanGeng picture TayYuanGeng  路  3Comments

NickITGuy picture NickITGuy  路  3Comments

alabuzhev picture alabuzhev  路  3Comments

zadjii-msft picture zadjii-msft  路  3Comments