Skip to content
Daniel Nachun edited this page Mar 18, 2024 · 1 revision

Why use zsh?

Zshell (usually abbreviated to zsh) is the shell of choice for this configuration. Zsh is mostly compatible with bash while also provides many features of csh and some other shells. Importantly, it also has an incredibly extensive set of plugins available that add many features not found in most, if any other shells.

Basic usage

Zsh does not have too many important key bindings in the base configuration. However a few key bindings are useful for navigating long lines:

  • Ctrl+f/Ctrl+b move forward one word and backwards one word, respectively.
  • Ctrl+a/Ctrl+e move to the beginning and end of the line, respectively.
  • Up/Down arrows to show previous and next commands in your history (Down will only have an effect if you've already pressed Up at least once)
  • Tab/Shift+Tab to cycle through autocompletion options - note that this can become very slow when there are many options, especially if those options are file names on a slow file system.

Plugins

Zsh plugins are managed in this configuration by zinit.

zsh-autosuggestions is perhaps the single most useful plugin in the entirety of this configuration, and will massively and instantaneously improve your productivity. It is inspired by a similar feature built into fish, an alternative shell with many nice features that is less compatible with bash. It is a very simple to plugin to use - as you start typing, it will search through your command history and suggest the command that most closely matches what you've typed. If you want to use the suggestion, there are several options:

  • Use Ctrl+e to move the end of the line to accept the entire suggestion - you would use this if you are trying to run exactly the same command you ran previously
  • Use Ctrl+f to accept the next word of the suggestion. Use this when you only want to use part of a suggestion instead of the whole thing.
  • If you want to change something in the middle of a suggestion, it is usually easiest to use Ctrl+e to accept the whole suggestion first and then modify it afterward

zsh-history-substring-search is perhaps the second most useful plugin after zsh-autosuggestions. It allows you search through your history using substring matching. Like zsh-autosuggestions, it was inspired by similar features in fish. This is extremely useful when you remember part of a command or a file name but not the whole thing. To use it, type the part you do remember and then:

  • Use Ctrl+p to search "up" for the most recent command containing that substring. Continue pressing Ctrl+p to search further in back in the history
  • Use Ctrl+n to go back down in your history after pressing Ctrl+p at least once. You may have to use both Ctrl+p and Ctrl+n to move up and down in your history to find the right command you want

zsh-vim-mode NOTE: this will soon be replaced by https://github.com/jeffreytse/zsh-vi-mode

zsh-vim-mode provides the option to edit zsh commands on the fly using neovim/vim key bindings (see Movement section in Neovim page. This can be much more efficient than the standard readline-style key bindings (see Basic Usage section).

  • To enter vi-mode, use Esc.
  • To enter visual mode from vi-mode, use v
  • To return to insert mode, use i/a/I/A (see Modes section in Neovim page)

Powerlevel10k is a sophisticated, highly configurable prompt for zsh which is responsible for all of the eye candy. Please visit the linked page for more details on what the different segments mean and how to further customize it.

zsh-syntax-highlighting provides on-the-fly syntax highlighting for your shell commands as you type them. Like zsh-autosuggestions, it is inspired by similar functionality in fish. The most important feature is that commands which are found in your path are highlighted in green, and commands which are not found are highlighted in red. A command may not be in your path because it is not installed, or because you have made a typo.