Useful resources:

Oh My Zsh terminal looks like the following, and your VS Code terminal will also inherit the same style.

Besides its good looks, Oh My Zsh is a framework for managing your zsh configuration, and it comes with a lot of helpful functions, helpers, plugins, themes.

Some useful plugins:

  • git: provides a lot of helpful aliases and functions for git commands.
  • Syntax highlighting: zsh-syntax-highlighting and fast-syntax-highlighting
  • Vim keybindings: vi-mode
  • Command auto-completion: zsh-autocomplete and zsh-autosuggestions

Oh My Zsh plugin directory:

  • ~/.oh-my-zsh/plugins/ (for built-in plugins) 自带插件目录

  • ~/.oh-my-zsh/custom/plugins/ (for custom plugins) 用户自定义插件目录

    $ZSH_CUSTOM is created by Oh My Zsh and points to ~/.oh-my-zsh/custom/.

    Oh My Zsh will automatically load plugins from this directory.

    To install a plugin, git clone the plugin repository to this directory.

    git clone <plugin-repo-url> $ZSH_CUSTOM/plugins/<plugin-name>
    

Q: How to install a plugin?
A: For custom plugins,

  1. git clone the plugin directory into ~/.oh-my-zsh/custom/plugins/.
  2. Add the plugin name to the plugins=(...) line in ~/.zshrc file.
  3. source ~/.zshrc and you are good to go.

For built-in plugins, just follow steps 2 and 3 above.

Refer to zsh-syntax-highlighting for a detailed example of how to install a plugin.


zsh-syntax-highlighting

zsh-syntax-highlighting is a minimal plugin for Oh My Zsh that provides syntax highlighting for the zsh shell.

Once you have installed Oh My Zsh, you can check if you have installed zsh-syntax-highlighting by looking into the plugin directory.

  1. If you don’t see the zsh-syntax-highlighting folder there, you can install it by running the following command in your terminal:

    # Cloning the GitHub repository directly into the Oh My Zsh plugin directory:
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
    ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
    

    Do NOT install it via Homebrew if you are using Oh My Zsh, because Oh My Zsh won’t be able to find it automatically. ↩︎

  2. Then, enable syntax highlighter in your ~/.zshrc file: Find the plugins=(...) line and add zsh-syntax-highlighting at the end:

    plugins=( [plugins...] zsh-syntax-highlighting)
    

    Note that plugins are separated by spaces (do not use commas).

  3. Finally, reload Zsh by running source ~/.zshrc or restarting your terminal.
  4. Test if it works.

    echo "This is a test"
    

    If you see different colors for different parts of the command, it means syntax highlighting is working. It looks like the following on my machine:

    zsh-syntax-highlighting

    Valid commands are in green, strings in yellow, etc.

    Invalid commands will be highlighted in red.

It is possible you only install the plugin without Oh My Zsh, but then you need to configure it manually. Follow instructions on the GitHub page.

fast-syntax-highlighting: you can think of it as a patch for zsh-syntax-highlighting. A comparison between the two plugins can be found here.


vi-mode

vi-mode

Mode indicator

  • Normal mode: indicated by a red <<< mark on the right prompt; controlled by MODE_INDICATOR
  • Insert mode: No special indicator, controlled by INSERT_MODE_INDICATORS

If you set VI_MODE_SET_CURSOR=true, the cursor will change shape to indicate the mode:

  • Normal mode: solid block
  • Insert mode: vertical line

zsh-autocomplete

Install zsh-autocomplete with

git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $ZSH_CUSTOM/plugins/zsh-autocomplete

Add to ~/.zshrc:

plugins=( [plugins...] zsh-autocomplete)

Resource ~/.zshrc:

source ~/.zshrc

zsh-autosuggestions: Autocomplete commands based on your history.

Use arrow keys to navigate through suggestions and hit Enter to accept the suggestion.


Git

git is one of the built-in plugins. You can enable it by adding git to the plugins=(...) line in your ~/.zshrc file. It provides a lot of helpful aliases and functions for git commands.

The Git aliases I use most frequently are as follows:

  • ga and gaa: the aliases for git add & git add --all

  • gcmsg: the alias for git commit --message


FAQ

Q: How to disable Oh My Zsh auto update check?
A: Open ~/.zshrc file and add the following line:

zstyle ':omz:update' mode disabled  # disable automatic updates

You can manually update by running omz update in your terminal.


ref: