[ prev | next | top ]

## 14. Bindings

Each of the editor commands we have seen was actually a function bound by default to a certain key. The real names of the commands are:

`expand-or-complete` TAB `
push-line` ESC-Q `
run-help` ESC-H `
accept-and-hold` ESC-A `
quote-line` ESC-’

These bindings are arbitrary; you could change them if you want. For example, to bind `accept-line` to ˆZ:

    % bindkey ’ˆZ’ accept-line

Another idea would be to bind the delete key to `delete-char`; this might be convenient if you use ˆH for backspace.

    % bindkey ’ˆ?’ delete-char

Or, you could bind ˆXˆH to `run-help`:

    % bindkey ’ˆXˆH’ run-help

Other examples:

    % bindkey ’ˆXˆZ’ universal-argument
    % bindkey ’ ’ magic-space
    % bindkey -s ’ˆT’ ’uptime
    > ’
    % bindkey ’ˆQ’ push-line-or-edit

universal-argument multiplies the next command by 4. Thus ˆXˆZˆW might delete the last four words on the line. If you bind space to `magic-space`, then csh-style history expansion is done on the line whenever you press the space bar.

Something that often happens is that I am typing a multiline command and discover an error in one of the previous lines. In this case, `push-line-or-edit` will put the entire multiline construct into the editor buffer. If there is only a single line, it is equivalent to `push-line`.

The `-s` flag to `bindkey` specifies that you are binding the key to a string, not a command. Thus `bindkey -s ’ˆT’ ’uptime\n’` lets you VMS lovers get the load average whenever you press ˆT.

If you have a NeXT keyboard, the one with the `|` and `\` keys very inconveniently placed, the following bindings may come in handy:

    % bindkey -s ’\e/’ ’\\’
    % bindkey -s ’\e=’ ’|’

Now you can type ALT-/ to get a backslash, and ALT-= to get a vertical bar. This only works inside zsh, of course; `bindkey` has no effect on the key mappings inside `talk` or `mail`, etc.

Some people like to bind `ˆS` and `ˆQ` to editor commands. Just binding these has no effect, as the terminal will catch them and use them for flow control. You could unset them as stop and start characters, but most people like to use these for external commands. The solution is to set the NOFLOWCONTROL option. This will allow you to bind the start and stop characters to editor commands, while retaining their normal use for external commands.

[ prev | next | top ]