]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/lib/key-bindings.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / lib / key-bindings.zsh
1 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
2 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
3 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
4
5 # Make sure that the terminal is in application mode when zle is active, since
6 # only then values from $terminfo are valid
7 if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
8   function zle-line-init() {
9     echoti smkx
10   }
11   function zle-line-finish() {
12     echoti rmkx
13   }
14   zle -N zle-line-init
15   zle -N zle-line-finish
16 fi
17
18 # Use emacs key bindings
19 bindkey -e
20
21 # [PageUp] - Up a line of history
22 if [[ -n "${terminfo[kpp]}" ]]; then
23   bindkey -M emacs "${terminfo[kpp]}" up-line-or-history
24   bindkey -M viins "${terminfo[kpp]}" up-line-or-history
25   bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history
26 fi
27 # [PageDown] - Down a line of history
28 if [[ -n "${terminfo[knp]}" ]]; then
29   bindkey -M emacs "${terminfo[knp]}" down-line-or-history
30   bindkey -M viins "${terminfo[knp]}" down-line-or-history
31   bindkey -M vicmd "${terminfo[knp]}" down-line-or-history
32 fi
33
34 # Start typing + [Up-Arrow] - fuzzy find history forward
35 if [[ -n "${terminfo[kcuu1]}" ]]; then
36   autoload -U up-line-or-beginning-search
37   zle -N up-line-or-beginning-search
38
39   bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search
40   bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search
41   bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search
42 fi
43 # Start typing + [Down-Arrow] - fuzzy find history backward
44 if [[ -n "${terminfo[kcud1]}" ]]; then
45   autoload -U down-line-or-beginning-search
46   zle -N down-line-or-beginning-search
47
48   bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search
49   bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search
50   bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search
51 fi
52
53 # [Home] - Go to beginning of line
54 if [[ -n "${terminfo[khome]}" ]]; then
55   bindkey -M emacs "${terminfo[khome]}" beginning-of-line
56   bindkey -M viins "${terminfo[khome]}" beginning-of-line
57   bindkey -M vicmd "${terminfo[khome]}" beginning-of-line
58 fi
59 # [End] - Go to end of line
60 if [[ -n "${terminfo[kend]}" ]]; then
61   bindkey -M emacs "${terminfo[kend]}"  end-of-line
62   bindkey -M viins "${terminfo[kend]}"  end-of-line
63   bindkey -M vicmd "${terminfo[kend]}"  end-of-line
64 fi
65
66 # [Shift-Tab] - move through the completion menu backwards
67 if [[ -n "${terminfo[kcbt]}" ]]; then
68   bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete
69   bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete
70   bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete
71 fi
72
73 # [Backspace] - delete backward
74 bindkey -M emacs '^?' backward-delete-char
75 bindkey -M viins '^?' backward-delete-char
76 bindkey -M vicmd '^?' backward-delete-char
77 # [Delete] - delete forward
78 if [[ -n "${terminfo[kdch1]}" ]]; then
79   bindkey -M emacs "${terminfo[kdch1]}" delete-char
80   bindkey -M viins "${terminfo[kdch1]}" delete-char
81   bindkey -M vicmd "${terminfo[kdch1]}" delete-char
82 else
83   bindkey -M emacs "^[[3~" delete-char
84   bindkey -M viins "^[[3~" delete-char
85   bindkey -M vicmd "^[[3~" delete-char
86
87   bindkey -M emacs "^[3;5~" delete-char
88   bindkey -M viins "^[3;5~" delete-char
89   bindkey -M vicmd "^[3;5~" delete-char
90 fi
91
92 # [Ctrl-Delete] - delete whole forward-word
93 bindkey -M emacs '^[[3;5~' kill-word
94 bindkey -M viins '^[[3;5~' kill-word
95 bindkey -M vicmd '^[[3;5~' kill-word
96
97 # [Ctrl-RightArrow] - move forward one word
98 bindkey -M emacs '^[[1;5C' forward-word
99 bindkey -M viins '^[[1;5C' forward-word
100 bindkey -M vicmd '^[[1;5C' forward-word
101 # [Ctrl-LeftArrow] - move backward one word
102 bindkey -M emacs '^[[1;5D' backward-word
103 bindkey -M viins '^[[1;5D' backward-word
104 bindkey -M vicmd '^[[1;5D' backward-word
105
106
107 bindkey '\ew' kill-region                             # [Esc-w] - Kill from the cursor to the mark
108 bindkey -s '\el' 'ls\n'                               # [Esc-l] - run command: ls
109 bindkey '^r' history-incremental-search-backward      # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
110 bindkey ' ' magic-space                               # [Space] - don't do history expansion
111
112
113 # Edit the current command line in $EDITOR
114 autoload -U edit-command-line
115 zle -N edit-command-line
116 bindkey '\C-x\C-e' edit-command-line
117
118 # file rename magick
119 bindkey "^[m" copy-prev-shell-word
120
121 # consider emacs keybindings:
122
123 #bindkey -e  ## emacs key bindings
124 #
125 #bindkey '^[[A' up-line-or-search
126 #bindkey '^[[B' down-line-or-search
127 #bindkey '^[^[[C' emacs-forward-word
128 #bindkey '^[^[[D' emacs-backward-word
129 #
130 #bindkey -s '^X^Z' '%-^M'
131 #bindkey '^[e' expand-cmd-path
132 #bindkey '^[^I' reverse-menu-complete
133 #bindkey '^X^N' accept-and-infer-next-history
134 #bindkey '^W' kill-region
135 #bindkey '^I' complete-word
136 ## Fix weird sequence that rxvt produces
137 #bindkey -s '^[[Z' '\t'
138 #