olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~13,000 unique cloners as of May '24, 580+ Homebrew installs 6/23-6/24
https://zsh-abbr.olets.dev
Other
511 stars 18 forks source link

`zsh-abbr` not working when the `viins` keymap is selected #101

Closed tapyu closed 8 months ago

tapyu commented 8 months ago

Is there an existing issue for this?

Update the issue title

Expected Behavior

My zle-line-init() widget sets the the vi-like insert-mode keymap (viins) whenever a new command line starts to read a new line of input.

zle-keymap-select() {
  if [[ ${KEYMAP} == vicmd ]] ||
     [[ $1 = 'block' ]]; then
    echo -ne '\e[2 q' # use \e[1 to blinking
  elif [[ ${KEYMAP} == main ]] ||
       [[ ${KEYMAP} == viins ]] ||
       [[ ${KEYMAP} = '' ]] ||
       [[ $1 = 'beam' ]]; then
    echo -ne '\e[6 q'
  fi
}

zle-line-init() {
  zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
  # echo -ne "\e[6 q" # beam shape
}
zle -N zle-line-init
zle -N zle-keymap-select
echo -ne '\e[6 q' # Use beam shape cursor on startup. (use \e[5 for blinking beam shape
preexec() { echo -ne '\e[6 q' ;} # Use beam shape cursor for each new prompt.

I am not sure why, by it prevents zsh-abbr from working... Is that an unpredictable behavior?

Actual Behavior

The VI mode works as expect, but the zsh-abbr doesn't. However, when I went back from the vicmd keymap, I can use abbr.

Steps To Reproduce

  1. Check my .zshrc
  2. Follow the same steps you see on the GIF abbr

Environment

❯ abbr profile
zsh-abbr version 5.1.0
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
OSTYPE linux-gnu

Installation method

Manual

Installation method details

I have my own manual way to install my plugins. Check my dotfiles for more info.

Anything else?

I there is no incompatibility with any other plugin that I am using. AFAIK, the unique issue is with the the viins keymap.

olets commented 8 months ago

Thanks for the report!

Starting with a zshrc that has only the lines you shared under "Expected Behavior", adding viins key bindings works for me. Try adding

bindkey -M viins " " abbr-expand-and-space
bindkey -M viins "^M" abbr-expand-and-accept
tapyu commented 8 months ago

Yes, it worked. Thank you!

olets commented 8 months ago

Great! Added it to the documentation https://zsh-abbr.olets.dev/advanced.html#alternative-keymaps

olets commented 1 month ago

Belatedly acknowledging more contributors in https://github.com/olets/zsh-abbr#community and https://zsh-abbr.olets.dev/community/

Would you like to be added @tapyu ? If so, I'll have the all-contributors bot open a pull request. Then I'll tag you in it to review for correct info

tapyu commented 1 month ago

Hi!

At the moment I've been using https://github.com/MenkeTechnologies/zsh-expand instead of this repo. I kinda get used to it and I didn't have time to fiddle zsh codes anymore. So I cannot be a contributor at the moment. However, if I decide to go back to this plugin and start to make PRs, I would be interested in becoming a contributor. :)