Minimal vim inspired .zshrc

13 Sep 2021 in Odds and Ends

I realised when I got a new machine that my dotfiles are in pretty poor shape and that I'd like to rebuild them. I need to use the new machine before I'll have time to do so.

In order to carry on working, I put together a minimal .zshrc config file that captures 90% of my muscle memory when working on the terminal.

Here's the file, with added comments in case you're interested:

zsh
autoload -Uz compinit && compinit # Loads completion modules
setopt AUTO_MENU # Show completion menu on tab press
setopt ALWAYS_TO_END # Move cursor after completion
setopt COMPLETE_ALIASES # Allow autocompletion for aliases
setopt COMPLETE_IN_WORD # Allow completion from middle of word
setopt LIST_PACKED # Smallest completion menu
setopt AUTO_PARAM_KEYS # Intelligent handling of characters
setopt AUTO_PARAM_SLASH # after a completion
setopt AUTO_REMOVE_SLASH # Remove trailing slash when needed
autoload edit-command-line; zle -N edit-command-line
# brew install zsh-history-substring-search
. /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh
# brew install z
. /usr/local/etc/profile.d/z.sh
bindkey -v
bindkey -M viins 'jj' vi-cmd-mode # jj = <esc>
bindkey -M vicmd "v" edit-command-line # Press v in command mode to edit in vim
bindkey -M vicmd 'k' history-substring-search-up # Search backwards in history
bindkey -M vicmd 'j' history-substring-search-down # Search forwards in history
bindkey '^?' backward-delete-char # Enable backspace after vicmd
bindkey '^h' backward-delete-char
eval "$(starship init zsh)" # Bootstrap starship shell

The biggest thing I missed was bindkey -v to switch to vim key bindings and zsh-history-substring-search (I don't like to type things more than once).