Fish-like autosuggestions for zsh
Fish-like fast/unobtrusive autosuggestions for zsh.
It suggests commands as you type based on history and completions.
Requirements: Zsh v4.3.11 or later
As you type commands, you will see a completion offered after the cursor in a muted gray color. This color can be changed by setting the
variable. See configuration.
If you press the → key (
widget) or End (
widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.
If you invoke the
widget, it will partially accept the suggestion up to the point that the cursor moves to.
You may want to override the default global config variables. Default values of these variables can be found here.
Note: If you are using Oh My Zsh, you can put this configuration in a file in the
directory. See their comments on overriding internals.
to configure the style that the suggestion is shown with. The default is
, which will set the foreground color to color 8 from the 256-color palette. If your terminal only supports 8 colors, you will need to use a number between 0 and 7.
Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:
For more info, read the Character Highlighting section of the zsh manual:
Note: Some iTerm2 users have reported not being able to see the suggestions. If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are different.
: Chooses a suggestion based on what tab-completion would suggest. (requires
, but chooses the most recent match whose preceding history item matches the most recently executed command (more info). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as
For example, setting
will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine.
This plugin works by triggering custom behavior when certain zle widgets are invoked. You can add and remove widgets from these arrays to change the behavior of this plugin:
: Widgets in this array will clear the suggestion when invoked.
: Widgets in this array will accept the suggestion when invoked.
: Widgets in this array will execute the suggestion when invoked.
: Widgets in this array will partially accept the suggestion when invoked.
: Widgets in this array will not trigger any custom behavior.
Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked.
Note: A widget shouldn't belong to more than one of the above arrays.
to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20. This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
, suggestions can be fetched asynchronously. To enable this behavior, set the
variable (it can be set to anything).
(it can be set to anything) to disable automatic widget re-binding on each precmd. This can be a big boost to performance, but you'll need to handle re-binding yourself if any of the widget lists change or if you or another plugin wrap any of the autosuggest widgets. To re-bind widgets, run
to a glob pattern to prevent offering suggestions for history entries that match the pattern. For example, set it to
to never suggest any
commands from history. Or set to
to never suggest anything 50 characters or longer.
Note: This only affects the
to a glob pattern to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to
to disable completion suggestions for git subcommands.
Note: This only affects the
This plugin provides a few widgets that you can use with
: Accepts the current suggestion.
: Accepts and executes the current suggestion.
: Clears the current suggestion.
: Fetches a suggestion (works even when suggestions are disabled).
: Disables suggestions.
: Re-enables suggestions.
: Toggles between enabled/disabled suggestions.
For example, this would bind ctrl + space to accept the current suggestion.
bindkey '^ ' autosuggest-accept
If you have a problem, please search through the list of issues on GitHub to see if someone else has already reported it.
Before reporting an issue, please try temporarily disabling sections of your configuration and other plugins that may be conflicting with this plugin to isolate the problem.
When reporting an issue, please include:
configuration that will reproduce the problem. See this comment for a good example of what this means.
Remove the code referencing this plugin from
Remove the git repository from your hard drive
rm -rf ~/.zsh/zsh-autosuggestions # Or wherever you installed
Edit the source files in
from those source files.
Pull requests are welcome! If you send a pull request, please:
Tests are written in ruby using the [
](http://rspec.info/) framework. They use [
](https://tmux.github.io/) to drive a pseudoterminal, sending simulated keystrokes and making assertions on the terminal content.
Test files live in
. To run the tests, run
. To run a specific test, run
TESTS=spec/some\_spec.rb make test
. You can also specify a
binary to use by setting the
environment variable (ex:
TEST\_ZSH\_BIN=/bin/zsh make test
A docker image for testing is available on docker hub. It comes with ruby, the bundler dependencies, and all supported versions of zsh installed.
Pull the docker image with:
docker pull ericfreese/zsh-autosuggestions-test
To run the tests for a specific version of zsh (where
below is substituted with the contents of a line from the [
docker run -it -e TEST\_ZSH\_BIN=zsh-<version> -v $PWD:/zsh-autosuggestions zsh-autosuggestions-test make test </version>