Repository navigation
Description
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
- Open Apple Terminal app (I'm on macOS 13.5.1)
nu(if you're not already in it)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
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 #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?
Activity
fdncred commentedon Aug 31, 2023
Have you tried changing the cursor_shape in the config file to see if that makes any difference?
mb21 commentedon Aug 31, 2023
@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).
amtoine commentedon Aug 31, 2023
@mb21
is there any remaining issues here? 😋
mb21 commentedon Sep 4, 2023
yes, very much.
Both configuration options result in the cursor in vim always being the same in insert mode and edit mode, which makes the experience very disorienting.
It seems whatever nushell sets the cursor to before entering vim, that's the cursor you'll be stuck with in vim. So effectively changing the config doesn't fix anything. Am I making sense?
amtoine commentedon Sep 4, 2023
yup i misunderstood your last message, my bad 😌
i cannot reproduce this in Rio nor Alacritty, even if i use
in my config, i see the cursor change when changing mode 😕
maybe you could try with the latest
mainbranch of Nushell? with the terminal emulator, that's the only other obvious difference i see between our two setups 😋mb21 commentedon Sep 5, 2023
I just built from source from latest
mainand could reproduce there as well. Also, I tried iTerm2 and could reproduce there as well. 🤷🏽♂️mb21 commentedon Sep 7, 2023
I just tried with Apple Terminal on an older laptop with macOS 12.6.8 and it's the same.
Pretty sure nushell should "just" restore the cursor before entering vim and before exiting itself...
@nibon7 did something like that in reedline and that works for me (I added a screen-recording there). That commit seems to have made it into crossterm (crossterm-rs/crossterm#646) but not nushell? Or perhaps it doesn't apply in the case of entering vim?
nibon7 commentedon Sep 7, 2023
This setting has nothing to do with vim editor, but it does affect the behavior of reedline command line input.
mb21 commentedon Sep 7, 2023
@nibon7 yes I know. Sorry, didn't mean to @-mention you if you're not a nushell dev. Seems to me currently that both reedline and crossterm do the right thing...
nibon7 commentedon Sep 7, 2023
https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes#For_iTerm2_on_OS_X
@mb21 The link above might be what you need.
[-]Line- instead of block cursor in edit-mode in vim[/-][+]Cursor shape is stuck in vim when opening it from a nushell[/+][-]Cursor shape is stuck in vim when opening it from a nushell[/-][+]Cursor shape is stuck in vim when opening vim from a nushell[/+]4 remaining items
nibon7 commentedon Sep 8, 2023
It seems that vim doesn't set the cursor shape. You can use
:echo &t_SI,:echo &t_SRand:echo &t_EIto check whether the values oft_SI,t_SRandt_EIare empty.Nushell sets cursor shape by default (line in emacs mode, block in vi insert mode and underline in vi normal mode) and restores previous cursor shape after nushell session ends. This behavior can't be canceled even if you comment out
cursor_shapeblock in$HOME/.config/nushell/config.nu.mb21 commentedon Sep 9, 2023
@nibon7 Okay... so how does vim render the cursor then and why does it break when opened in nu? You can reproduce the problem on your machine? also macOS, or?
nibon7 commentedon Sep 9, 2023
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.
mb21 commentedon Sep 9, 2023
even if you open zsh or bash directly from your teminal emulator, not opening them from inside nushell?!
mb21 commentedon Sep 9, 2023
Are you sure? From the vim code you linked:
With e.g. T_CSR defined here.
And out_str says:
Also, for me this isn't isolated to vim. If I open bash or zsh from inside nushell, the cursor is wrong there as well (wrong meaning it's a line cursor although these shells normally have block cursors for me). In zsh/bash, I can fix it with
echo -e "\033[2 q". Actually I can fix it inside vim as well by running:! echo -e "\033[2 q"... but then it's just stuck as a block cursor which doesn't really help me either.nibon7 commentedon Sep 9, 2023
Yes
mb21 commentedon Sep 9, 2023
Ah, interestingly I have the same behaviour if I change the cursor to 'Vertical Bar' (default is 'Block') in my terminal emulator's preferences (Apple Terminal).
nibon7 commentedon Sep 9, 2023
Would you mind applying this patch to build nushell and test again?
mb21 commentedon Sep 9, 2023
Sure, I just tried the diff, and now the cursor is always a block cursor (in both nushell edit and insert mode and in vim edit and insert mode) 😅
Edit: actually it's always the cursor set in the terminal emulator's preferences... if I change that to 'line', it's line everywhere (and doesn't change in insert/edit mode).
mb21 commentedon Sep 9, 2023
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: blockin nushell config indeed gives me the same behaviour I have in bash/zsh... I'll investigate whether I can tweak my vimrc file...mb21 commentedon Sep 9, 2023
Okay, adding this to my vimrc actually works:
So actually there is no issue in nushell, sorry for the stir! I just assumed vim, bash and zsh must be managing their cursors actively, whereas all of them actually don't do anything at all and just carry on working with the cursor the shell has in which they were opened in. That's why changing the cursor shape in my nushell config affected them...
Not sure whether there should be a warning note somewhere in nushell docs, seeing that nushell is the only one that even in the default config changes the terminal's cursor actively to a line cursor, or whether that default should be reconsidered. But yeah, maybe I'm the only one who is so stupid :P
amtoine commentedon Sep 9, 2023
@mb21
maybe this could be added to the cookbook? 😋
Make cursor_shape optional (#10289)