Skip to main content

Using Zsh

Enabling Auto Suggestion in Zsh

Get command completion suggestions based on your command history.

By default, zsh can do the bash styled tab completion. However, you can take it to the next level by using the zsh-autosuggestions plugin. It will suggest commands based on the Zsh command history and you can autocomplete the suggestion by pressing the Tab key.

The final result looks like this:

Before you proceed to the how-to part, make sure you have installed Git in your system, and if not, here's how to install Git on Ubuntu:

sudo apt install git

In this tutorial, I will walk you through two ways you can enable auto-suggestion for tab completion in zsh:

  • For Oh My Zsh users
  • Manual installation

So let's start with the first one.

Method 1: For Oh My Zsh users

If you are already using Oh My Zsh, then enabling this feature is quite easy and can be done in two easy steps.

First, use the following command to download the auto-suggestions plugin from GitHub:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Now, open the zshrc file using the following command:

nano ~/.zshrc

In this config file, you'd have to find a line starting with plugins and add zsh-autosuggestions as shown here:

Finally, save changes and exit from the configuration file.

To take effect from the changes you've made, source the file using the following command:

source ~/.zshrc

That's it!

Method 2: Manual installation of zsh-autosuggestions

If you don't like to rely on Oh My Zsh to customize your zsh, then you can enable autosuggestion using manual installation.

For this, first, use the following command to clone the autosuggestion repo for the manual installation:

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions

Once done, open the zshrc file:

nano ~/.zshrc

Go to the end of the file in the nano editor by pressing Alt + / and paste the following lines:

source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
enable auto suggestion manually in zsh

Finally, save changes and exit from the nano editor.

Source the zshrc file to enable the auto-suggestions right now:

source ~/.zshrc

That's all it takes to enable auto suggestions in zsh manually.

We are on a road of solving problems that every beginner zsh faces, so if you have any topic suggestion, feel free to drop a comment.

Sagar Sharma