274ccc95e2306c65b0535bda50a0dbf30a74014e
[zsh.git] / .zsh / 55_KeyBindings.zsh
1 # -*- mode: sh;-*-
2
3 ###
4 # Key Bindings
5 # set to emacs style
6 bindkey -e
7 # change some defaults
8 bindkey '^Z' push-input # "suspend" current line
9 case "$TERM" in
10 linux) # Linux console
11 bindkey '\e[1~' beginning-of-line # Home
12 bindkey '\e[4~' end-of-line # End
13 bindkey '\e[3~' delete-char # Del
14 bindkey '\e[2~' overwrite-mode # Insert
15 ;;
16 screen) # The textmode window manager
17 # In Linux console
18 bindkey '\e[1~' beginning-of-line # Home
19 bindkey '\e[4~' end-of-line # End
20 bindkey '\e[3~' delete-char # Del
21 bindkey '\e[2~' overwrite-mode # Insert
22 bindkey '\e[7~' beginning-of-line # home
23 bindkey '\e[8~' end-of-line # end
24 # In rxvt
25 bindkey '\eOc' forward-word # ctrl cursor right
26 bindkey '\eOd' backward-word # ctrl cursor left
27 ;;
28 rxvt*)
29 bindkey '\e[7~' beginning-of-line # home
30 bindkey '\e[8~' end-of-line # end
31 bindkey '\eOc' forward-word # ctrl cursor right
32 bindkey '\eOd' backward-word # ctrl cursor left
33 bindkey '\e[3~' delete-char
34 bindkey '\e[2~' overwrite-mode # Insert
35 ;;
36 *xterm*)
37 bindkey '\e[H' beginning-of-line # Home
38 bindkey '\e[F' end-of-line # End
39 # I need the next two when in rxvt via ssh.
40 bindkey '\e[7~' beginning-of-line # home
41 bindkey '\e[8~' end-of-line # end
42 bindkey '\e[3~' delete-char # Del
43 bindkey '\e[2~' overwrite-mode # Insert
44 bindkey "^[[5C" forward-word # ctrl cursor right
45 bindkey "^[[5D" backward-word # ctrl cursor left
46 ;;
47 esac
48
49 #k# Insert a timestamp on the command line (yyyy-mm-dd)
50 zle -N insert-datestamp
51 bindkey '^Ed' insert-datestamp
52
53 #k# Put the current command line into a \kbd{sudo} call
54 zle -N sudo-command-line
55 bindkey "^Os" sudo-command-line
56
57 ## This function allows you type a file pattern,
58 ## and see the results of the expansion at each step.
59 ## When you hit return, they will be inserted into the command line.
60 if is4 && zrcautoload insert-files && zle -N insert-files; then
61 #k# Insert files and test globbing
62 bindkey "^Xf" insert-files ## C-x-f
63 fi
64
65 ## This set of functions implements a sort of magic history searching.
66 ## After predict-on, typing characters causes the editor to look backward
67 ## in the history for the first line beginning with what you have typed so
68 ## far. After predict-off, editing returns to normal for the line found.
69 ## In fact, you often don't even need to use predict-off, because if the
70 ## line doesn't match something in the history, adding a key performs
71 ## standard completion - though editing in the middle is liable to delete
72 ## the rest of the line.
73 if is4 && zrcautoload predict-on && zle -N predict-on; then
74 #zle -N predict-off
75 bindkey "^X^R" predict-on ## C-x C-r
76 #bindkey "^U" predict-off ## C-u
77 fi
78
79 # used when you press M-? on a command line
80 alias which-command='whence -a'
81
82 # in 'foo bar | baz' make a second ^W not eat 'bar |', but only '|'
83 # this has the disadvantage that in 'bar|baz' it eats all of it.
84 typeset WORDCHARS='|'$WORDCHARS
85
86 # press ctrl-x ctrl-e for editing command line in $EDITOR or $VISUAL
87 if is4 && zrcautoload edit-command-line && zle -N edit-command-line; then
88 bindkey '\C-x\C-e' edit-command-line
89 fi
90
91 # move cursor between chars when typing '', "", (), [], and {}
92 magic-single-quotes() { if [[ $LBUFFER[-1] == \' ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
93 magic-double-quotes() { if [[ $LBUFFER[-1] == \" ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
94 magic-parentheses() { if [[ $LBUFFER[-1] == \( ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
95 magic-square-brackets() { if [[ $LBUFFER[-1] == \[ ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
96 magic-curly-brackets() { if [[ $LBUFFER[-1] == \{ ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
97 magic-angle-brackets() { if [[ $LBUFFER[-1] == \< ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
98 bindkey \' magic-single-quotes
99 bindkey \" magic-double-quotes
100 bindkey \) magic-parentheses
101 bindkey \] magic-square-brackets
102 bindkey \} magic-curly-brackets
103 bindkey \> magic-angle-brackets
104 zle -N magic-single-quotes
105 zle -N magic-double-quotes
106 zle -N magic-parentheses
107 zle -N magic-square-brackets
108 zle -N magic-curly-brackets
109 zle -N magic-angle-brackets
110
111 # Show what the completion system is trying to complete with at a given point
112 bindkey '^Xh' _complete_help