Terminal: Weird behavior after changing cursor shape in vim

Created on 23 Mar 2020  路  2Comments  路  Source: microsoft/terminal

Environment

Windows build number: 10.0.18363.0
Windows Terminal version (if applicable): 0.10.761.0

Steps to reproduce

  1. Launch vim from either WSL or SSH of a Linux host
  2. Set cursor shape options: blinking block in normal mode, blinking vertical bar in insert mode
let &t_SI .= "\<Esc>[5 q"
let &t_EI .= "\<Esc>[0 q"

The shape does change as what we expect, but I observed weird behaviors after that.

Expected behavior

  1. When exiting insert mode, i.e. press i then \, the cursor stays at where it was if I didn't move it.
  2. When exiting insert mode, the cursor shape should change as soon as \ pressed.
  3. Restore the default shape after exiting vim

Actual behavior

  1. Press i then \, the cursor moves ahead one character.
  2. The shape didn't change until the next blink.
  3. The cursor stays like a block after exiting.
Needs-Tag-Fix Resolution-By-Design

Most helpful comment

  1. You can find an explanation of why the cursor moves backwards on the VIM stack exchange site. This is expected behaviour, and I see the same behaviour in other terminals emulators too.
  2. The delayed shape changing is because an ESC character can also be the start of a character sequence representing another key, so VIM needs to wait and see if there are more characters following before it can be certain you've actually pressed Esc. Again, this is expected behaviour.
  3. DECSCUSR 0 is officially defined as the block cursor so that's why you get a block on exit. Some terminals do interpret that as the user's preferred cursor, though, and it's possible we may support that one day too (see issue #1604)

All 2 comments

  1. You can find an explanation of why the cursor moves backwards on the VIM stack exchange site. This is expected behaviour, and I see the same behaviour in other terminals emulators too.
  2. The delayed shape changing is because an ESC character can also be the start of a character sequence representing another key, so VIM needs to wait and see if there are more characters following before it can be certain you've actually pressed Esc. Again, this is expected behaviour.
  3. DECSCUSR 0 is officially defined as the block cursor so that's why you get a block on exit. Some terminals do interpret that as the user's preferred cursor, though, and it's possible we may support that one day too (see issue #1604)

Thanks for the comprehensive writeup, James. :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickITGuy picture NickITGuy  路  3Comments

mrmlnc picture mrmlnc  路  3Comments

alabuzhev picture alabuzhev  路  3Comments

dev-logan picture dev-logan  路  3Comments

waf picture waf  路  3Comments