aboutsummaryrefslogtreecommitdiffstats
path: root/zsh/keybindings.zsh
blob: 863858998e238d4c6053d56d9b82c726bb9d7ce4 (plain)
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
##
# Keybindings
#


# Make sure the terminal is in application mode when zle is active. Only then
# are the values from $terminfo valid.
function zle-line-init () {
	printf '%s' "${terminfo[smkx]}"
}
function zle-line-finish () {
	printf '%s' "${terminfo[rmkx]}"
}
zle -N zle-line-init
zle -N zle-line-finish
zle -N edit-command-line

bindkey -v

# Shift-tab
bindkey $terminfo[kcbt] reverse-menu-complete

# Insert
bindkey -M vicmd $terminfo[kich1] vi-insert
bindkey          $terminfo[kich1] overwrite-mode

# Delete
bindkey -M vicmd $terminfo[kdch1] vi-delete-char
bindkey          $terminfo[kdch1] delete-char

# Home
bindkey -M vicmd $terminfo[khome] vi-beginning-of-line
bindkey          $terminfo[khome] beginning-of-line

# End
bindkey -M vicmd $terminfo[kend] vi-end-of-line
bindkey          $terminfo[kend] vi-end-of-line

# Backspace (and <C-h>)
bindkey -M vicmd $terminfo[kbs] backward-char
bindkey          $terminfo[kbs] backward-delete-char

# Page up (and <C-b> in vicmd)
bindkey -M vicmd $terminfo[kpp] beginning-of-buffer-or-history
bindkey          $terminfo[kpp] beginning-of-buffer-or-history
bindkey -M vicmd '^B'           beginning-of-buffer-or-history

# Page down (and <C-f> in vicmd)
bindkey -M vicmd $terminfo[knp] end-of-buffer-or-history
bindkey          $terminfo[knp] end-of-buffer-or-history

# Do history expansion on space
bindkey ' ' magic-space
#
# Use M-w for small words
bindkey '^[w' backward-kill-word
bindkey '^W' vi-backward-kill-word

bindkey -M vicmd '^H' backward-char
bindkey          '^H' backward-delete-char

# h and l whichwrap
bindkey -M vicmd 'h' backward-char
bindkey -M vicmd 'l' forward-char

# Incremental undo and redo
bindkey -M vicmd '^R' redo
bindkey -M vicmd 'u' undo

# Misc
bindkey -M vicmd 'ga' what-cursor-position

# Open in editor
bindkey -M vicmd 'v' edit-command-line

# History search
bindkey '^P' up-line-or-search
bindkey '^N' down-line-or-search

# Patterned history search with zsh expansion, globbing, etc.
bindkey -M vicmd '^R' history-incremental-pattern-search-backward
bindkey          '^R' history-incremental-pattern-search-backward

# Verify search result before accepting
bindkey -M isearch '^M' accept-search