Skip to content
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

ZVM_MODE mismatch & escape sequences no longer working #309

Open
3 tasks done
taylrfnt opened this issue Jan 2, 2025 · 2 comments
Open
3 tasks done

ZVM_MODE mismatch & escape sequences no longer working #309

taylrfnt opened this issue Jan 2, 2025 · 2 comments

Comments

@taylrfnt
Copy link

taylrfnt commented Jan 2, 2025

General information

  • Terminal program: ghostty 1.0.1 (xterm-ghostty)
  • Operating system: macOS 15.1.1 (24B91)
  • ZSH framework:
  • ZSH version: zsh 5.9 (arm64-apple-darwin24.0)
  • ZVM version: zsh-vi-mode 0.11.0

Basic examination

  • I have read through the README page
  • I have the latest version of zsh-vi-mode
  • I have tested with another terminal program

Problem description

Using a vanilla install, no custom keybinds or anything special, just sourcing via the homebrew steps on the README and a few prompt re-drawings to work with oh-my-posh. If I execute a command while remaining in normal mode (example steps below), the prompt temporarily reflects insert, then overrides to "normal" (the last mode), even though I am still in "insert" mode. In addition, this state is not escapable with any escape mappings (Esc or Ctrl+[), and is only fixed by re-initializing the shell via something like exec zsh or quitting my terminal emulator & restarting. Screen recording below:

zsh-vi-mode-bug-repo.mov

I think this is related to the usage of ZVM_MODE_LAST in the ZVM_LINE_INIT_MODE here, but I have not had a moment to investigate in detail given I have a workaround (just making sure I am in insert mode prior to executing any command 😄 ).

Reproduction steps

  1. Open terminal
  2. Execute something other than a normal insert mode (e.g. search command then execute result)
  3. Get stuck in "normal" (really insert) mode until reinitializing the shell

Expected behavior

I'd expect one of two behaviors:

  1. The ZVM_MODE value retains the last mode and that mode is actually what the user is in (e.g. if normal, then normal keybinds should work, not the insert ones)
  2. ZVM_MODE value is overwritten to insert after each command executes (technically after the previous command exits, I suppose).
@taylrfnt
Copy link
Author

taylrfnt commented Jan 2, 2025

I was able to reproduce this in iTerm, Ghostty, and Kitty, so I do not think this is anything related to Ghostty (I know it's still new on the scene). I also did not start with inserting text into the buffer after getting "stuck" in normal mode in my recording, but that's how I initially figured out I was in insert rather than normal mode.

Also, here's my functions in my .zshrc, for reference:

bindkey -v
_omp_redraw-prompt() {
  local precmd
  for precmd in "${precmd_functions[@]}"; do
    "$precmd"
  done

  zle .reset-prompt
}

export POSH_VI_MODE="insert"

function zvm_after_select_vi_mode() {
  case $ZVM_MODE in
  $ZVM_MODE_NORMAL)
    POSH_VI_MODE="normal"
    ;;
  $ZVM_MODE_INSERT)
    POSH_VI_MODE="insert"
    ;;
  $ZVM_MODE_VISUAL)
    POSH_VI_MODE="visual"
    ;;
  $ZVM_MODE_VISUAL_LINE)
    POSH_VI_MODE="visual-line"
    ;;
  $ZVM_MODE_REPLACE)
    POSH_VI_MODE="replace"
    ;;
  esac
  _omp_redraw-prompt
}

@taylrfnt
Copy link
Author

taylrfnt commented Jan 2, 2025

After some further testing & reconfiguration, I am able to achieve Expected Behavior Option 2: revert to insert at the exit of previous command, regardless of the last mode state prior to execution, by changing the value of the following:

# Set the line init mode (empty will keep the last mode)
# you can also set it to others, such as $ZVM_MODE_INSERT.
 : ${ZVM_LINE_INIT_MODE:=$ZVM_MODE_INSERT}

Using the zvm_config function is probably a much easier and better way to do this, for anyone coming across this later.

For my use case, always defaulting to insert mode works just fine. The default configuration does move to normal mode after command exit as I mentioned in Case 1 of the expected behavior; however, I can't quite piece together why I can insert when ZVM_MODE is set to normal. Admittedly this is not an area I am very skilled with but I will try to keep digging to see if I can identify if this is a personal config issue or something deeper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant