This guide will help you in learning the art of highlighting the syntax in Zsh on your MacOS.
How to Highlight Syntax in Zsh on Mac?
You can highlight syntax in Zsh from the following two methods:
Method 1: How to Highlight Syntax in Zsh Using Extension?
There is an extension, which you can easily install and use in Zsh to highlight syntax. The complete step-by-step process to install and use the extension method for syntax highlighting in Zsh is given below:
Step 1: Open Zsh terminal and execute the below-given command to download Zsh syntax highlighting extension source file from GitHub website.
Step 2: Now open the Zsh configuration file called zshrc on your terminal using the following command:
Step 3: Then add the following line at the end of the zshrc file, as shown below:
Step 4: Save the file using Ctrl+X keys, add Y, and enter to exit. Then reload the changes to the source file to enable the Zsh syntax highlighting feature on your Mac system.
Here are the snapshots of the terminal before and after enabling the syntax highlighting feature in Zsh.
Before Syntax Highlighting
After Syntax Highlighting
2: How to Highlight Syntax in Zsh Using Oh My Zsh Plugins?
You can also install Oh My Zsh on the terminal and use its plugins option to highlight syntax in Zsh; this can be done through the following steps:
Step 1: First, install Oh My Zsh on Mac from here.
Step 2: Then use the following git command to clone the Oh My Zsh syntax highlighting feature for Zsh.
Step 3: Open the zshrc configuration from the following command:
Step 4: Inside the source file, search plugins option using Ctrl+W and then add the following line right in front of the plugins, inside the bracket after the git keyword as shown below:
Step 5: Save the file using Ctrl+X keys, add Y, and enter to exit. Then reload the changes and enable the syntax highlighting feature from the following command:
The following are snapshots that are taken before and after performing syntax highlighting in Zsh from Oh My Zsh plugins.
Before Syntax Highlighting
After Syntax Highlighting
Conclusion
The syntax highlighting feature in Zsh is crucial since it allows you to recognize and colorize various parts of your commands or syntax. There are two easy methods to highlight syntax in Zsh, one is using the extension and the other is using Oh My Zsh plugins. Both methods require cloning the source file from the GitHub website and adding a line inside the zshrc file to enable the highlight feature in Zsh. The above guide has presented a detailed step-by-step tutorial to easily use both these methods on your Mac terminal to quickly highlight syntax in Zsh.