initial
[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*|rxvt)
37 bindkey '\e[H' beginning-of-line # Home
38 bindkey '\e[F' end-of-line # End
39 bindkey '\e[3~' delete-char # Del
40 bindkey '\e[2~' overwrite-mode # Insert
41 bindkey "^[[5C" forward-word # ctrl cursor right
42 bindkey "^[[5D" backward-word # ctrl cursor left
43 ;;
44 esac
45
46 #k# Insert a timestamp on the command line (yyyy-mm-dd)
47 zle -N insert-datestamp
48 bindkey '^Ed' insert-datestamp
49
50 #k# Put the current command line into a \kbd{sudo} call
51 zle -N sudo-command-line
52 bindkey "^Os" sudo-command-line
53
54 ## This function allows you type a file pattern,
55 ## and see the results of the expansion at each step.
56 ## When you hit return, they will be inserted into the command line.
57 autoload -U insert-files
58 zle -N insert-files
59 bindkey "^Xf" insert-files ## C-x-f
60
61 ## This set of functions implements a sort of magic history searching.
62 ## After predict-on, typing characters causes the editor to look backward
63 ## in the history for the first line beginning with what you have typed so
64 ## far. After predict-off, editing returns to normal for the line found.
65 ## In fact, you often don't even need to use predict-off, because if the
66 ## line doesn't match something in the history, adding a key performs
67 ## standard completion - though editing in the middle is liable to delete
68 ## the rest of the line.
69 autoload -U predict-on
70 zle -N predict-on
71 #zle -N predict-off
72 bindkey "^X^R" predict-on ## C-x C-r
73 #bindkey "^U" predict-off ## C-u
74
75 # used when you press M-? on a command line
76 alias which-command='whence -a'
77
78 # in 'foo bar | baz' make a second ^W not eat 'bar |', but only '|'
79 # this has the disadvantage that in 'bar|baz' it eats all of it.
80 typeset WORDCHARS='|'$WORDCHARS
81
82 autoload -U edit-command-line
83 zle -N edit-command-line
84 bindkey '\C-x\C-e' edit-command-line