Trigger accept on `l` in normal mode? #137
vi-forward-char should be bound to autosuggest-accept by default.
https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/config.zsh#L31
Yes, but for some reason, it doesn't seem to be accepting the suggestion. Could it be because zsh doesn't consider the CURSOR to be at the EOL in vicmd?
Yeah, that's definitely the problem. I think this should fix it:
diff --git a/src/widgets.zsh b/src/widgets.zsh
index 3c15788..246283f 100644
--- a/src/widgets.zsh
+++ b/src/widgets.zsh
@@ -30,23 +30,27 @@ _zsh_autosuggest_modify() {
fi
}
# Accept the entire suggestion
_zsh_autosuggest_accept() {
- # Only accept if the cursor is at the end of the buffer
- if [ $CURSOR -eq $#BUFFER ]; then
+ # Save location of the cursor so we can compare later
+ local original_cursor=$CURSOR
+
+ # Original widget moves the cursor
+ _zsh_autosuggest_invoke_original_widget $@
+
+ # Only accept if the cursor has not moved (is at the end of the buffer)
+ if [ $CURSOR -eq $original_cursor ]; then
# Add the suggestion to the buffer
BUFFER="$BUFFER$POSTDISPLAY"
# Remove the suggestion
unset POSTDISPLAY
# Move the cursor to the end of the buffer
CURSOR=${#BUFFER}
fi
-
- _zsh_autosuggest_invoke_original_widget $@
}
# Accept the entire suggestion and execute it
_zsh_autosuggest_execute() {
# Add the suggestion to the bufferDoes this branch fix the problem for you?
https://github.com/zsh-users/zsh-autosuggestions/tree/fixes/vi-next-char_to_accept
Meh... I'm actually not sure how much I like this solution. Is there a good way of checking if the user is currently in vim mode?
It looks like $KEYMAP is only available inside zle-keymap-select, called when the keymap changes.
But it looks like we can get what we need from the bindkey command.
‘bindkey -lL main’ shows which keymap is linked to ‘main’, if any, and hence if the standard emacs or vi emulation is in effect.
http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
% bindkey -v
% bindkey -lL main
bindkey -A viins main
% bindkey -e
% bindkey -lL main
bindkey -A emacs mainLooks like we should be able to see if vicmd is enabled, and change the logic accordingly.
Actually it does look like $KEYMAP is available in any zle widget, but it is always set to main, even after setting vi mode with bindkey -v.
Ah! When you're actually in vicmd (not viins), $KEYMAP is actually set to vicmd instead of main. Should be able to use that.
In fish, if I hit l (move right) at the end of the buffer while a completion is visible, it accepts the entire completion. I am able to get zsh-autosuggestions to complete when using the right arrow key, but it doesn't work with using l at the end of the buffer.
Is it possible to replicate this behavior?