So, why move away? The short answer is “bloat”. I find myself using oh-my-zsh only for prompt themes, colored man pages, etc. Yet there are 286 plugins in total, waiting for me to enable them.
What are my essentials?
- A nice prompt.
- No duplicate history when reverse-searching my commands.
- Case insensitive completion.
- Emacs-style keybindings in zsh’s command line editor (the place where you type out the commands).
- Zsh syntax highlighting.
I uninstalled oh-my-zsh. The next step is to put back the five essentials listed above into my .zshrc file.
A nice prompt
This one is easy — I just need my prompt to be shortened and easy to notice.
PROMPT='%F{green}%n%f@%F{green}%m%f %F{red}%~%b%f %# '
No duplicate history when reverse-searching my commands
This one is pretty simple, too. I added the following lines in my .zshrc and it solved the problem of having duplicate command history when you press the up-arrow or Ctrl-r to search for commands. These are just built-in zsh parameters for us to tune. Anywhere you see the term hist, it means “history”.
HISTSIZE=200
HISTFILE=~/.zsh_history
SAVEHIST=200
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt incappendhistory
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
Case insensitive completion
Put these two lines somewhere in your .zshrc and you’re done:
autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
Emacs-style keybindings
I know my way around the Emacs-style keybindings. Here are a couple of them that I find especially useful.
Ctrl-a: jump to line beginning (same as pressing Home).
Ctrl-e: jump to line end (same as pressing End).
Alt-backspace: backspaces a whole word.
Ctrl-k: delete from current position to end-of-line.
Ctrl-a Ctrl-k: delete whole line (it’s a combination of “jump to line beginning” and “delete from current position to end-of-line”)
Alt-b: jump left a whole word
Alt-f: jump right a whole word
Many shells (e.g. bash) already use Emacs-style keybindings by default. If you still want to explicitly set it, here’s how:
bindkey -e
If you’re a die-hard vim fan, feel free to set
bindkey -v
Zsh Syntax Highlighting
My final goal on my essential list is to enable syntax highlighting in the zsh command line editor. For instance, when I type an invalid command, it would be red, and when I type a correct command, such as “ls” or “cd”, it’d be green.
This can save you the hassle of pressing Enter and only then finding out the command you typed had a typo.
To enable this cool little feature, we need to install this package, which is conveniently named zsh-syntax-highlighting. Follow the official guide to install the package for your operating system, and add a line or two to enable the feature in your .zshrc.
Since I’m using a Mac, I would first install zsh-syntax-highlighting using Homebrew and then add the following line to the bottom of my zsh configuration file:
Install (Debian)
sudo nala install zsh-syntax-highlighting -y
Install (Homebrew)
brew install zsh-syntax-highlighting
Manual Install (Git)
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.config/zsh/zsh-syntax-highlighting
add this line to the end of your .zshrc file
source ~/.config/zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
add to end of .zshrc
Zsh-Autosuggestions
Recently, I discovered this excellent plugin and enabled it too. This provides Fish-like fast/unobtrusive autosuggestions for zsh. It suggests commands as you type based on history and completions.
Install (Debian)
sudo nala install zsh-autosuggestions -y
Install (Homebrew)
brew install zsh-autosuggestions
Manual Install (Git)
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.config/zsh/zsh-autosuggestions
add this line to the end of your .zshrc file
source ~/.config/zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
add to end of .zshrc
Concluding words
If you were an "oh-my-zsh" user and followed everything in this article, congratulations! Your shell should feel more snappy and responsive.