-
Notifications
You must be signed in to change notification settings - Fork 27
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
Workaround to use surrounds while keeping KEYTIMEOUT=1 #33
Comments
Thank you, Freddie! This is a nice hack. It is a little too hairy for me to want to put it in the plugin, but I think I could mention this issue in the README as another option for people to try. |
Heey, happy new year!! 🎉 When I first wrote the code I wasn't sure if it would work correctly, but now after 5 months using it, I can say that it works perfectly! It's a bit shady to understand how it works, but it works. Hahaha |
@FreddieOliveira Thanks for your hack, it works! I have a question if you have a chance to read ...
Everything I use works well, except If you have a chance, maybe you can try to reproduce it on your ZSH. If you could reproduce it, maybe you have any ideas on how to fix it ? Thank you so much @FreddieOliveira for your solution. |
Hey @korniychuk, good to know it was helpful! I've been using this hack up to these days and never had any problems. I also couldn't reproduce your issue, probably it's another part of your code that's causing it. Could you share the whole file? |
@korniychuk It's not clear to me what you expect the behavior to be when typing |
Thank you for so quick response! And sorry for my delay. Tomorrow I'll try to find time to record a video reproducing the issue and prepare a minimal |
@softmoth Thanks for your comment. Maybe I'm wrong, I'll try to explain. Expected behavior: Current behavior:
Demo: Shortest config to reproduce: export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(zsh-vim-mode)
function change-hack() {
read -k 1 option
if [[ $option == 's' ]]; then
zle -U Tcs
elif [[ $option == 'c' ]]; then
zle vi-change-whole-line
else
zle -U ${NUMERIC}Tvc$option
fi
}
function delete-hack() {
read -k 1 option
if [[ $option == 's' ]]; then
zle -U Tds
elif [[ $option == 'd' ]]; then
zle kill-whole-line
else
zle -U ${NUMERIC}Tvd$option
fi
}
function yank-hack() {
read -k 1 option
if [[ $option == 's' ]]; then
zle -U Tys
elif [[ $option == 'y' ]]; then
zle vi-yank-whole-line
else
zle -U ${NUMERIC}Tvy$option
fi
}
zle -N change-hack
zle -N delete-hack
zle -N yank-hack
autoload -Uz surround
zle -N delete-surround surround
zle -N change-surround surround
zle -N add-surround surround
bindkey -M vicmd 'Tcs' change-surround
bindkey -M vicmd 'Tds' delete-surround
bindkey -M vicmd 'Tys' add-surround
bindkey -M vicmd 'Tvd' vi-delete
bindkey -M vicmd 'Tvc' vi-change
bindkey -M vicmd 'Tvy' vi-yank
bindkey -M vicmd 'c' change-hack
bindkey -M vicmd 'd' delete-hack
bindkey -M vicmd 'y' yank-hack
bindkey -M visual S add-surround
source $ZSH/oh-my-zsh.sh @FreddieOliveira Maybe I'm mistaking and your hack just doesn't fix |
@korniychuk Verify you've set But if |
Wow! It works, removing Thank you @softmoth ! 🙏 |
This isn't actually a issue, it's more like an informative notice. All workarounds presented in the README.md has one or other drawback, but the one showed bellow adresses this issue flawless (or I think so).
The strategy is to remap the
c
,d
andy
keys to user defined widgets, thus removing its original bindingsvi-delete
,vi-change
andvi-yank
.These widgets will then read the next character pressed and if its an
s
, it will call thesurround
widget, otherwise it will call thevi
widget with the proper numeric-argument. One special attention must be given to repeated key commands, likecc
,dd
andyy
, so it won't call our widget recursively.Here's the code:
This workaround has two advantages over the others:
KEYTIMEOUT
doesn't interfere on its working;The only drawback is the ugly hack it is itself.
Note, however, that I came up with this yesterday night, so it wasn't tested throughout. Pls, let me know if something doesn't work.
The text was updated successfully, but these errors were encountered: