Zsh-autosuggestions: How to autocomplete only part of command?

Created on 13 Aug 2017  Â·  11Comments  Â·  Source: zsh-users/zsh-autosuggestions

Is there a way to autocomplete only part of command? Currently pressing -> will autocomplete the entire command, is there a key shortcut to only compete to the next tab?

Most helpful comment

hi @AnthonyWC, there is no need to configure it like that. You just need to bind a key to one of the following weights:

  • forward-word
  • vi-forward-word
  • vi-forward-word-end
  • vi-forward-blank-word
  • vi-forward-blank-word-end

for example, if you want to use ctrl + space to invoke the autocomplete, run bindkey '^ ' forward-word will do the job.

All 11 comments

Check out the "partial-accept" functionality in the readme. You can add widgets that move the cursor forward to ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS to have them accept the suggestion as far as the cursor is moved.

Hi @ericfreese, so I followed this post from you (https://github.com/zsh-users/zsh-autosuggestions/issues/93#issuecomment-175939916) that mentioned so I added it in .zshrc & always try to run commands directly in terminal:

# Remove forward-char widgets from ACCEPT
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=("${(@)ZSH_AUTOSUGGEST_ACCEPT_WIDGETS:#forward-char}")

# Add forward-char widgets to PARTIAL_ACCEPT
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS+=(forward-char)

But I still don't see a change in behaviour; I tried also starting a new session:

echo $ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
end-of-line vi-forward-char vi-end-of-line vi-add-eol

echo $ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
forward-word vi-forward-word vi-forward-word-end vi-forward-blank-word vi-forward-blank-word-end forward-char

Did I miss something?

p.s. I also see various reference to vi-NAME-X and I happen to have vi-mode enabled for zsh; I wonder if that will cause have any relevant for this?

hi @AnthonyWC, there is no need to configure it like that. You just need to bind a key to one of the following weights:

  • forward-word
  • vi-forward-word
  • vi-forward-word-end
  • vi-forward-blank-word
  • vi-forward-blank-word-end

for example, if you want to use ctrl + space to invoke the autocomplete, run bindkey '^ ' forward-word will do the job.

@GeniusV Thank you very much for the tip!

with MacOS 10.13.6 and iTerm2, I found "ctrl + →" doing the forward-word, and "→" getting to the end of prompt line by default settings, so you don't need to set it at all.

with MacOS 10.13.6 and iTerm2, I found "ctrl + →" doing the forward-word, and "→" getting to the end of prompt line by default settings, so you don't need to set it at all.
in linux,it works well too.

On macOS 10.15.5 with iTerm2 and Oh My Zsh! I found Option + f moves forward by one word.

Is there a way to accept backwards? Like if I press ctrl + <right arrow> too many times?
A backward-word would be great

@himat backward-kill-word widget should do the trick. Ctrl + w in emacs mode.

Couldn't get control+left to work for partial match on mac with iterm2

Here are my settings...

echo $ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
forward-word emacs-forward-word vi-forward-word vi-forward-word-end vi-forward-blank-word vi-forward-blank-word-end vi-find-next-char vi-find-next-char-skip
echo $ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
forward-char end-of-line vi-forward-char vi-end-of-line vi-add-eol

Since find-word is in the array I would expect control+f to go a word at a time.

I was able to get it to work on mac with control+f and control+b in my .zshrc

bindkey '^f'   backward-word        
bindkey '^b'   forward-word           

The only other binding that worked (without any changes) was control+[ then press f
Would love to find out how to get this working with arrows on mac

Ok anyone struggling with this for iTerm2 see the following...
https://stackoverflow.com/questions/6205157/iterm-2-how-to-set-keyboard-shortcuts-to-jump-to-beginning-end-of-line

option+arrow works after using that solution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hiteshsharma picture hiteshsharma  Â·  5Comments

metalmac picture metalmac  Â·  4Comments

sebw picture sebw  Â·  6Comments

clay-f picture clay-f  Â·  7Comments

kergoth picture kergoth  Â·  3Comments