Oh My Zsh
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-highlightingandfast-syntax-highlighting - Vim keybindings:
vi-mode - Command auto-completion:
zsh-autocompleteandzsh-autosuggestions
Oh My Zsh plugin directory:
-
~/.oh-my-zsh/plugins/(for built-in plugins) 自带插件目录 -
~/.oh-my-zsh/custom/plugins/(for custom plugins) 用户自定义插件目录$ZSH_CUSTOMis 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,
git clonethe plugin directory into~/.oh-my-zsh/custom/plugins/.- Add the plugin name to the
plugins=(...)line in~/.zshrcfile. source ~/.zshrcand 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.
-
If you don’t see the
zsh-syntax-highlightingfolder 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-highlightingDo NOT install it via Homebrew if you are using Oh My Zsh, because Oh My Zsh won’t be able to find it automatically. ↩︎
-
Then, enable syntax highlighter in your
~/.zshrcfile: Find theplugins=(...)line and addzsh-syntax-highlightingat the end:plugins=( [plugins...] zsh-syntax-highlighting)Note that plugins are separated by spaces (do not use commas).
- Finally, reload Zsh by running
source ~/.zshrcor restarting your terminal. -
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:
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
- Normal mode: indicated by a red
<<<mark on the right prompt; controlled byMODE_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:
-
gaandgaa: the aliases forgit add&git add --all -
gcmsg: the alias forgit 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: