-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Cursor shape is stuck in vim when opening vim from a nushell #10169
Comments
Have you tried changing the cursor_shape in the config file to see if that makes any difference? cursor_shape: {
emacs: underscore # block, underscore, line, blink_block, blink_underscore, blink_line (line is the default)
vi_insert: block # block, underscore, line , blink_block, blink_underscore, blink_line (block is the default)
vi_normal: line # block, underscore, line, blink_block, blink_underscore, blink_line (underscore is the default)
} |
@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). |
@mb21 |
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? |
yup i misunderstood your last message, my bad 😌 i cannot reproduce this in Rio nor Alacritty, even if i use cursor_shape: {
vi_insert: block
vi_normal: block
} in my config, i see the cursor change when changing mode 😕 maybe you could try with the latest |
I just built from source from latest |
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? |
This setting has nothing to do with vim editor, but it does affect the behavior of reedline command line input. |
@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... |
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. |
@nibon7 thanks, but that's not it, it's definitely a bug in nushell. Since amtoine above already was confused as well, I've updated this issue's title and initial description to make it clearer what the problem is (now that I understand it better). Is it clearer now? |
Thanks, I get it now :) |
What's the fix? |
It seems that vim doesn't set the cursor shape. You can use |
It seems that vim doesn't set the cursor shape. You can use 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 |
@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? |
I guess the cursor is rendered in the follow code: 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. |
even if you open zsh or bash directly from your teminal emulator, not opening them from inside nushell?! |
Are you sure? From the vim code you linked: if (*T_CSR != NUL)
p = T_CSR; // Replace mode cursor
else
p = T_CSI; // fall back to Insert mode cursor
if (*p != NUL)
{
out_str(p); 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 |
Yes |
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). |
Would you mind applying this patch to build nushell and test again? diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs
index 415778448..ab6d788bb 100644
--- a/crates/nu-cli/src/repl.rs
+++ b/crates/nu-cli/src/repl.rs
@@ -268,8 +268,7 @@ pub fn evaluate_repl(
)))
.with_quick_completions(config.quick_completions)
.with_partial_completions(config.partial_completions)
- .with_ansi_colors(config.use_ansi_coloring)
- .with_cursor_config(cursor_config);
+ .with_ansi_colors(config.use_ansi_coloring);
perf(
"reedline builder",
start_time, |
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). |
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 |
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 |
# Description There are several cursor shape related issues #7151 #9243 #7271 #8452 #10169, you can't disable the cursor shape feature even if you comment out the entire `cursor_shape` block in the config.nu, and even worse, when nushell exits with an error, the cursor shape can't be restored, that is annoying. This PR provides an opportunity to disable setting the cursor shape. # User-Facing Changes If you use the default config.nu, nothing changes, but if you comment out `cursor_shape` block or set them to `inherit`, related cursor shape will not be set. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
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
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
Additional context
Interestingly if I enter
zsh
from inside anu
shell, and then entervim
, the cursor is still broken. But if I entervim
directly fromzsh
(without going throughnu
) the cursor is correctly a block cursor.This seems related to #8452, as I can get it fixed inside a
zsh
shell insidenu
by resetting the cursor withecho -e "\033[2 q"
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):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?The text was updated successfully, but these errors were encountered: