dotfiles/.zshrc
Martin Büchler bfb508733e feat(zsh): add sensible keybinds for navigation, editing, history, completion, and autosuggestions
Improves productivity and usability for both emacs and vi mode users.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>
2025-08-07 23:07:35 +02:00

130 lines
2.8 KiB
Bash

# =====================
# Environment settings
# =====================
# Do Not Track for CLI tools
export DO_NOT_TRACK=1
# Preferred editor
export EDITOR='nvim'
# =====================
# Prompt and UI
# =====================
# Starship prompt (modern, fast, customizable)
eval "$(starship init zsh)"
# =====================
# fzf integration
# =====================
# fzf key bindings and completion
if [ -f /usr/share/fzf/key-bindings.zsh ]; then
source /usr/share/fzf/key-bindings.zsh
fi
if [ -f /usr/share/fzf/completion.zsh ]; then
source /usr/share/fzf/completion.zsh
fi
# =====================
# Aliases
# =====================
# Modern replacements for coreutils
alias cat="bat"
alias ls="exa --icons"
alias ll="exa -l --icons"
alias la="exa -la --icons"
# Developer tools
alias lg="lazygit"
# =====================
# Zsh history settings
# =====================
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt append_history
setopt inc_append_history
setopt share_history
setopt hist_ignore_dups
setopt hist_reduce_blanks
# =====================
# Zsh plugin integrations
# =====================
# Autosuggestions
if [ -f /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
# Accept autosuggestion with Ctrl+F or Right Arrow
bindkey '^F' autosuggest-accept
bindkey '^[[C' autosuggest-accept
fi
# Syntax highlighting
if [ -f /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
# Additional completions
fpath+=/usr/share/zsh/site-functions
autoload -Uz compinit && compinit
# =====================
# Sensible keybinds
# =====================
# Emacs mode by default (comment out for vi mode)
bindkey -e
# Uncomment below for vi mode
# bindkey -v
# History search
bindkey '^R' history-incremental-search-backward
bindkey '^S' history-incremental-search-forward
# Navigation
bindkey '^A' beginning-of-line
bindkey '^E' end-of-line
bindkey '^[b' backward-word
bindkey '^[f' forward-word
# Editing
bindkey '^U' kill-whole-line
bindkey '^W' backward-kill-word
bindkey '^K' kill-line
bindkey '^Y' yank
# Completion
bindkey '^I' expand-or-complete
bindkey '^ ' menu-complete
# fzf keybinds (if fzf is loaded)
if [ -n "$FZF_TMUX" ] || [ -f /usr/share/fzf/key-bindings.zsh ]; then
# Ctrl+T: fzf file search
bindkey '^T' fzf-file-widget
# Ctrl+R: fzf history search (already set above)
# Alt+C: fzf cd widget
bindkey '^[c' fzf-cd-widget
fi
# =====================
# Command-not-found handler (Arch/pkgfile)
# =====================
if [ -f /usr/share/doc/pkgfile/command-not-found.zsh ]; then
source /usr/share/doc/pkgfile/command-not-found.zsh
fi
# =====================
# End of .zshrc
# =====================