nushell: Cursor shape is stuck in vim when opening vim from a nushell

Describe the bug

When opening vim (or zsh or bash) from nushell, the cursor stays stuck to whatever it was in the nushell session (block or line cursor). Inside vim, switching between edit- and insert-mode doesn’t change the cursor either, which is very disorienting.

I even temporarily removed my ~/.vimrc file to make sure it’s not related to that.

How to reproduce

  1. Open Apple Terminal app (I’m on macOS 13.5.1)
  2. nu (if you’re not already in it)
  3. vim (I used the macOS-supplied one at /usr/bin/vim)

Observe that cursor is a vertical line (or whatever it was you had nu’s cursor configured to). Pressing i puts me into insert mode but the cursor doesn’t change.

Expected behavior

I expect a block curstor in vim edit mode. More generally, I expect a program (like zsh or bash) when its opened from inside nu to be able to set its own cursor.

Screenshots

image

Configuration

key value
version 0.84.0
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.71.1 (eb26296b5 2023-08-03) (built from a source tarball)
cargo_version cargo 1.71.2 (1a737af0c 2023-08-07)
build_time 2023-08-22 21:09:23 +00:00
build_rust_channel release
allocator standard
features dataframe, default, sqlite, trash, which, zip
installed_plugins

Additional context

Interestingly if I enter zsh from inside a nu shell, and then enter vim, the cursor is still broken. But if I enter vim directly from zsh (without going through nu) the cursor is correctly a block cursor.

This seems related to https://github.com/nushell/nushell/issues/8452, as I can get it fixed inside a zsh shell inside nu by resetting the cursor with echo -e "\033[2 q"

> nu
> zsh # cursor is still a line cursor here although usually it's a block cursor for me in zsh
> vim # line cursor
> echo -e "\033[2 q"
>
> vim # cursor is block now (both in insert mode and edit mode though)

Finally, If I put the following into my config.nu, the cursor is always a block cursor inside vim as well (in both insert and edit mode):

  edit_mode: vi,
  cursor_shape: {
    vi_insert: block,
    vi_normal: block,
  },

So definitely seems to have something to do with how nu shell sets the cursor. Seems whatever it’s doing should be undone before entering vim and before exiting nushell?

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 26 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@mb21 maybe this could be added to the cookbook? 😋

Oh, I just realized that when I open vim in zsh/bash, the cursor is always a block cursor there as well, also in insert mode! Sorry, I was sure I had tested that before.

So it seems vim (and bash and zsh) just don’t alter the terminal cursor on startup… but vim assumes it to be a block cursor? Using vi_insert: block in nushell config indeed gives me the same behaviour I have in bash/zsh… I’ll investigate whether I can tweak my vimrc file…

I guess the cursor is rendered in the follow code: https://github.com/vim/vim/blob/7bcd25cad3e9d5c9e25c7ae2bde67285c26f73cd/src/term.c#L4309-L4355

In my gentoo system, whether in nushell or zsh or even bash, the cursor shape in vim editor doesn’t change when entering or leaving insert mode with the default config.

Thanks, I get it now 😃

I just built from source from latest main and could reproduce there as well. Also, I tried iTerm2 and could reproduce there as well. 🤷🏽‍♂️

@fdncred thanks for the quick reply! I just updated the post above with something that does fix it. With your snippet, the cursor stays an underline in vim (in both insert and edit mode).