Autosuggestions do not work with zsh-syntax-highlighting #6
Also when I move the cursor with forward-char or vi-add-eol part that was (but after move is not) highlighted in gray is still highlighted in gray.
Ok, those two cases should be fixed now. Can you update and try again?
No. It appears that there are other widgets for moving around that you did not cover.
ZLE_AUTOSUGGEST_ACCEPT_WIDGETS should probably also contain end-of-line, vi-end-of-line, vi-forward-blank-word, vi-forward-blank-word-end, vi-find-next-char, vi-find-next-char-skip, emacs-forward-word, vi-forward-word-end, vi-goto-column, vi-goto-mark, vi-goto-mark-line, vi-repeat-find, vi-rev-repeat-find. I have listed here all widgets that seem to be (not sure about marks, otherwise that “are” and not “seem to be”) able to move cursor forward.
But if I add all these widgets with
diff --git a/autosuggestions.zsh b/autosuggestions.zsh
index f650486..1ece5ba 100644
--- a/autosuggestions.zsh
+++ b/autosuggestions.zsh
@@ -37,7 +37,10 @@ accept-and-menu-complete
ZLE_AUTOSUGGEST_ACCEPT_WIDGETS=(
vi-forward-char forward-char vi-forward-word forward-word vi-add-eol
-vi-add-next vi-forward-blank-word
+vi-add-next vi-forward-blank-word end-of-line vi-end-of-line
+vi-forward-blank-word vi-forward-blank-word-end vi-find-next-char
+vi-find-next-char-skip emacs-forward-word vi-forward-word-end vi-goto-column
+vi-goto-mark vi-goto-mark-line vi-repeat-find vi-rev-repeat-find
)
autosuggest-pause() {
@@ -52,7 +55,7 @@ autosuggest-pause() {
zle -A autosuggest-accept-line-orig accept-line
for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS $ZLE_AUTOSUGGEST_SUSPEND_WIDGETS $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
[[ -z $widgets[$widget] || -z $widgets[autosuggest-${widget}-orig] ]] &&\
- continue
+ continue
eval "zle -A autosuggest-${widget}-orig ${widget}"
done
autosuggest-highlight-suggested-textI have a problem with custom vi-ctrl-o widget (I get “No such widget `autosuggest-vi-ctrl-o-orig'”) (I move cursor with a vi-ctrl-o widget that invokes whatever widget is bound to the next key in vicmd keymap). Interesting that zsh-syntax-highlighting backups this widget (I guess it just hooks every widget). My widget looks like this:
function _-vi-digit-arg ()
{
emulate -L zsh
[[ -z "${NUMERIC}" ]] && NUMERIC=0
[[ -z "$1" ]] && num=0 || num=$(( $1 ))
shift
(( NUMERIC=NUMERIC*10+num )) && $@
}
function _-vi-ctrl-o()
{
emulate -L zsh
local keystr
read -k keystr
local -r keystr
local -ri key=$(( #keystr ))
if (( key==##A )) ; then zle end-of-line
elif (( key==##$ )) ; then zle end-of-line
elif (( key==##I )) ; then zle vi-first-non-blank
elif (( key==##d )) ; then _-vi-delete
elif (( key==##0 )) && [[ -z $NUMERIC ]] ;
then zle beginning-of-line
elif (( key>=##0 && key<=##9 ))
then _-vi-digit-arg $(( key - ##0 )) _-vi-ctrl-o
elif (( key==##s )) ; then zle perlsubstitute
elif (( key==##= )) ; then zle tailfor
else
zle ${${(z)$(bindkey -M vicmd $keystr)}[2]}
fi
}Yes, I've read zsh-syntax-highlighting source code and it binds to all widgets, even user-defined one. Unfortunately I cant do that because it would break a lot of editing behavior. Eg: go in normal mode and edit a previous character would 'unmaterialize' whatever is to the right of the cursor(accept-line would kill that part unless the cursor was explicitly moved to the end of the line).
The best solution I found to cover most cases is simple:If any of the widgets in ZLE_AUTOSUGGEST_SUSPEND_WIDGETS are executed, autosuggestions is temporarily disabled until a character is inserted at the end of the line.
Clearly we need a more generic/better logic to decide when pausing/resuming autosuggestions should happen. I'm gonna try to come up with something this week, but if you have ideas I'm all ears :)
hello, how can fix this issue for me ?
roko__@CLDX [ 18:36:26 ] [ 08/07/14 ] [ pts/3 ] ~ % nano .zshrc
No such widget `.autosuggest-forward-char-orig'
@tarruda I'm experiencing the same problem :( Have to live on detached HEAD because up-to-date versions of zsh-autosuggestions and zsh-syntax-highlighting don't play well together. Is there any chance you could look into this problem once again, please?
Is there any chance you could look into this problem once again, please?
Not in the foreseeable future, sorry.
@balta2ar we need someone with time & zsh experience to refactor some of this
Just in case others are struggling with this one while using prezto. If when you submit commands with active auto-suggestions, they loose their highlighting and get confusing with the actual command that was run:

(notice, I had typed and submitted git a, while the rest was grayed out before submitting)
The following syntax-highlighting cleared the issue for me:
https://github.com/sorin-ionescu/prezto/tree/master/modules/syntax-highlighting#highlighting


It is somewhat expected since both plugins are using the same zle widgets. I guess you need to cooperate and work out some standard that will allow using both plugins.
Fish has both completion and highlighting and it looks nice. I do not like much more limited capabilities of it though.