-
Notifications
You must be signed in to change notification settings - Fork 6
/
.zshrc
154 lines (129 loc) · 4.42 KB
/
.zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Executes commands at the start of any interactive session.
# Shell options, functions, and aliases go here!
# Environment variables do *not* go here. They go in .zprofile.
#
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# no ding!
ZBEEP=""
# allow variables in PS1
setopt PROMPT_SUBST
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt COMPLETE_IN_WORD # tab in the middle of a word works correctly!
setopt ALWAYS_TO_END
setopt INTERACTIVE_COMMENTS # sometimes I copy-paste comments
setopt NOMATCH # refuse to use ambiguous globs
setopt CHASE_DOTS # resolve ".." paths textually, not physically
setopt AUTO_CD # using a directory as a command implies "cd"
unsetopt EXTENDED_GLOB # weird zsh-specific globbing
unsetopt BEEP # no, thanks
unsetopt NOTIFY # background jobs' status waits for prompt
HISTFILE="$HOME/.zsh_history"
function history() {
if [[ "$#" -eq 0 ]] ; then
# Modify default options.
set -- -LDi -n
fi
builtin history "$@"
}
. ~/.sh_rc
# enable advanced command completion: fpath must be set before "compinit"
fpath+=(
~/.zsh_completion
"$HOMEBREW_PREFIX"/completions/zsh
"$HOMEBREW_PREFIX"/share/zsh/site-functions
)
autoload -Uz compinit
compinit
zstyle ':completion:*' insert-unambiguous yes
zstyle ':completion:*' verbose yes
zstyle ':completion:*' select yes
## this causes ambiguous completions:
#zstyle ':completion:*' menu yes
zkbd_dir="${ZDOTDIR:-$HOME}/.zkbd"
zkbd_file="$zkbd_dir/$TERM-$VENDOR-$OSTYPE"
ln -sf $zkbd_file $zkbd_dir/$TERM.tmp
if ! [[ "$(grep -c '^key\[' "$zkbd_file")" -eq 24 ]]; then
autoload zkbd && zkbd
fi
if [[ -e "$zkbd_file" ]]; then
source "$zkbd_file"
fi
# reset and enable vim bindings
bindkey -d
bindkey -v
# Anoyances:
# allow backspace after vi-A
bindkey "$key[Backspace]" backward-delete-char
# backspace doesn't work if you were ever in normal mode
bindkey "^?" backward-delete-char
bindkey "^W" backward-kill-word
bindkey "^H" backward-delete-char
bindkey "^U" backward-kill-line
# tab completion is over-eager
unsetopt MENU_COMPLETE
setopt AUTO_MENU
bindkey "^[[Z" reverse-menu-complete
# default vim bindings can't move cursor left to previous line
bindkey "^[OC" forward-char
bindkey "^[OD" backward-char
bindkey "^[OF" end-of-line
bindkey "^[OH" beginning-of-line
bindkey "^[[3~" delete-char
bindkey "^[[C" forward-char
bindkey "^[[D" backward-char
# fix home/end keys
bindkey "$key[Home]" beginning-of-line
bindkey "$key[End]" end-of-line
bindkey -a "$key[Home]" beginning-of-line
bindkey -a "$key[End]" end-of-line
# esc-v to edit command in vim
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# jj for normal mode
bindkey 'jj' vi-cmd-mode
# ctrl-w remove word backwards
bindkey '^w' backward-kill-word
# ctrl-r starts searching history backward
bindkey '^s' history-incremental-pattern-search-forward
bindkey '^r' history-incremental-pattern-search-backward
# Use vim cli mode
bindkey '^P' up-history
bindkey '^N' down-history
# this makes more sense, to me:
bindkey -a '/' history-incremental-pattern-search-forward
bindkey -a '?' history-incremental-pattern-search-backward
# up and down keys only search through the local history
# use ctrl-P/N for shared history {
up-line-or-local-history() {
zle set-local-history -n 1
zle up-line-or-history
zle set-local-history -N
}
zle -N up-line-or-local-history
bindkey "$key[Up]" up-line-or-local-history
bindkey -a "k" up-line-or-local-history
down-line-or-local-history() {
zle set-local-history -n 1
zle down-line-or-history
zle set-local-history -N
}
zle -N down-line-or-local-history
bindkey "$key[Down]" down-line-or-local-history
bindkey -a "j" down-line-or-local-history
# opam configuration
if [ -r ~/.opam/opam-init/init.zsh ]; then
. ~/.opam/opam-init/init.zsh
fi
if [ -e "$HOME/private-dotfiles/.zshrc" ]; then
source "$HOME/private-dotfiles/.zshrc"
fi