-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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 can't be changed #4335
Comments
It appears that Vim doesn't do this unless it's been explicitly configured to do so: vimwiki/Configuring the cursor. When I set the options for changing the cursor shape, it works properly. Can you confirm the part of your vim config that exchanges the cursor options? |
For what it's worth, I can't reproduce this issue even outside of Windows Terminal. |
BashPowershellVim informationIn case something's wrong with vim: In the old terminalin the old terminal What other info might be useful? |
Ah, it looks like the documentation here is confusing. The There may be an issue in the regular expression. My configuration looks like this: if &term =~ '^xterm'
" solid underscore
let &t_SI .= "\<Esc>[4 q"
" solid block
let &t_EI .= "\<Esc>[2 q"
" 1 or 0 -> blinking block
" 3 -> blinking underscore
" Recent versions of xterm (282 or above) also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
endif |
And lastly, Windows vim (the one you're using from powershell) uses a different system to set the cursor. I think there's an open duplicate bug for that one not working 100% with Terminal. 😄 |
It worked, thanks! I'm leaving this code for the lost souls that might search it How to change cursor in vim in windows terminalWorks for vim in wsl (not powershell) In this example, normal mode is a block, insert mode is a vertical bar
|
Thanks for following up! I'm going to close this one since it's answered. |
So the config posted by @eduardoarandah works in vim but appears to have the side effect of leaving the cursor in whatever state it was when Vim exited (most likely a block in normal mode), so the terminal ends up with a block cursor rather than the default. (This is in ubuntu running in WSL) |
Confirmed what @lllama is seeing: when I exit vim from normal mode, the Terminal cursor is not a block cursor. This works fine in conhost consoles (cmd, powershell, pwsh). |
Here's a workaround for resetting the cursor to a vertical bar after exiting vim. Add this to your .bashrc so that it will set the cursor to a blinking bar every time it renders a prompt. (Other styles are listed in this StackOverflow answer)
|
Closing this as solved is kind of frustrating, as the original issue was reported for Powershell sessions, while the "solution is" basically, "don't use powershell, use linux", which isn't reaaally the answer I'd hope for. Ideally running vim in a powershell session would be comfortable without having to use WSL. |
@chadmoore while I agree with you, just wanted to add that you can do something similar in PowerShell if you overwrite your The default is: "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " Based on https://docs.microsoft.com/windows/console/console-virtual-terminal-sequences#simple-cursor-positioning and using `e (PowerShell Core; see about_Special_Characters), something like this should work in your $profile: function prompt {
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) `e[?12h"
} I say should, but in testing the cursor didn't blink in Windows Terminal. Other cursor sequences worked, so this appears to be a bug in Windows Terminal. |
@chadmoore for the record, this thread was specifically tracking "setting the cursor in the WSL vim", not
I'm actually not sure that there's a duplicate for that issue, since I couldn't find it from some trivial searching. That should probably be moved out to it's own issue (which will likely end up as a bug on |
I had the same problem @lllama and @heaths had (cursor stuck as block in terminal). The code below from stackoverflow allowed me to recover the cursor without modifying my .bashrc as @dennisjlee suggested.
|
so this is the best solution: if &term =~ '^xterm'
" enter vim
autocmd VimEnter * silent !echo -ne "\e[3 q"
" oherwise
let &t_EI .= "\<Esc>[3 q"
" insert mode
let &t_SI .= "\<Esc>[5 q"
" 1 or 0 -> blinking block
" 2 -> solid block
" 3 -> blinking underscore
" 4 -> solid underscore
" Recent versions of xterm (282 or above) also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
" leave vim
autocmd VimLeave * silent !echo -ne "\e[5 q"
endif |
To follow up on this is there any way to have Vim use the MS Terminal vintage thick underline instead of the thin underline? In practice I've found the block cursor in Vim with the MS Terminal to be not usable because the MS Terminal doesn't invert the color of the character under the block cursor so you often get into situations where you can't read the character under the block. For now I've been using the vintage thick underline cursor but I haven't been able to find a code to set that. The thin underline is a bit too hard to see, especially when recording video tutorials. |
I encountered the problem that an escape sequence is output at starting Vim. " HACK: Work around the problem that an escape sequence is output at startup.
" https://vi.stackexchange.com/questions/19748
autocmd VimEnter * normal :startinsert
" suspend and resume vim
nnoremap <silent> <C-z> :execute 'silent !echo -en "\e[5 q"'<CR>:suspend<Bar>:execute 'silent !echo -en "\e[0 q"'<CR> |
The solution pasted by @gao-lex does not work for me, is it only for WSL? I'm using PowerShell and cmd.exe: In PowerShell or cmd.exe, normal mode cursor is block, insert mode cursor is underscore. I can be sure that |
For me also none of the solutions work. This is the last issue I have with Vim on Windows (and well maybe that pasting from clipboard is not in line). |
I should note that for whatever reason using option 0 does not give blinking block in wsl and still outputs a vertical bar. So replace
|
There was a long discussion about cursor style 0 vs. 1 vs. empty, in #1604. |
Doesn't work for me :( |
Sometimes I use wsl with VcXsrv, and that means everything works fine. Sometimes I use wsl inside of Windows Terminal. It's the same vimrc either way. I can't use My vim has a light color scheme, and it fails to change the color or shape of the Windows terminal cursor. So the cursor becomes literally 100% invisible when using vim. The situation is pretty dire. |
I had the same issue. The easiest workaround is to set However, this will affect the entire profile instead of just vim. |
This worked for me, I'm using PowerShell: |
(Issue) cursor does not reset on exiting from vim - microsoft/terminal#4335 (Issue : #5)
(Issue) cursor does not reset on exiting from vim - microsoft/terminal#4335
why: to distinguish between command and normal modes of vi mode in powershell how: using VimLeave event and guicursor option misc: see :help guicursor links: - neovim/neovim#4867 - microsoft/terminal#4335 tags: cursor,cursor-shape fixes #5
why: to distinguish between command and normal modes of vi mode in powershell how: using VimLeave event and guicursor option misc: see :help guicursor links: - neovim/neovim#4867 - microsoft/terminal#4335 tags: cursor,cursor-shape fixes #5
It works, but vim does not attempt to restore cursor shape on exit. |
@gao-lex Thanks a Lot for this One 🫂 |
I've been looking for the setting for Vim for Windows (cmd.exe and powershell version) but cannot find them. Could somebody tell me? I have this set for Vim on Linux/WSL, and it works, but not on Windows Terminal cmd.exe or powershell.
|
The use case permutations are very vast and most posters report on one instance only. SolutionThe following solution pertains to:
Create a file called .vimrc in your home directory C:\Users\Elmo with following content
6:vert-bar,4:underscore,2:block are the non-blinking cursors for the three vim modes. This will make vim use the mode dependent cursors.
Add the following function
That echo is a command to tell powershell to set the cursor to 5:blinking-vertical-bar in this case. Save. Exit. Known ProblemWhen starting vim from Powershell through Windows Terminal the initial cursor should be block, non-blinking, however it's the vertical bar blinking (whatever came from the prompt). Once you change modes, the expected vim cursors will be used. Already Tried, Don't BotherUsing the VimLeave event in .vimrc to execute set cursor
Like to mark this useful. |
@iovuio Thank you for this information, but adding the following to my
It does change the cursor on Vim on Linux/WSL though (I had already had it set). I just thought that my setup may differ because I use clink. Maybe this is having an effect? I can't think of any reason why this setting wouldn't work for me if it is the correct one to be used on Vim for Windows when using Windows Terminal. |
I had a specific setting for Command Prompt in Windows Terminal to use a Bar cursor. With this set the cursor in Vim for Windows was also always a vertical bar. I have now changed that setting to 'Filled Box'. Now while the cursor is a flashing square block in the shell, in Vim for Windows it's the same in Normal Mode and in Insert Mode it has changed to a flashing underscore. Not quite what it is set as (both modes flashing and underscore instead of vertical bar in Insert Mode), but at least there is a difference between Normal and Insert modes. This will do, as I don't often use this version of vim anyway. |
According to the Vim documentation, it should be applied after executing let &t_SI = "\e[6 q"
let &t_SR = "\e[4 q"
let &t_EI = "\e[2 q"
" when entering vim
let &t_ti ..= "\e[2 q"
" when leaving vim
let &t_te ..= "\e[5 q"
|
Environment
Steps to reproduce
Expected behavior
In old terminal you know when you're in normal mode
Actual behavior
Cursor can't be changed, so it's hard to work
The text was updated successfully, but these errors were encountered: