### Copyright (C) 1995-1997 Jesper K. Pedersen
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


proc bindings {} {
  # command line editor / bindings

  Desc "Here you configure the bindings of the keys in the command line"\
      "editor see the 'Editing' section in the tcsh manual for more"\
      "information. To see which bindings are default type \"bindkey\""\
      "in the shell."
  
  ShortDesc "Bindings for the command line editor"

  ############################### Widgets ##############################
  CheckBox changeEditor \
    -text "Change Default Editor"
  
  Radio mode \
      -text "Which default bindings:" \
      -entries emacs vi -packFrame:fill x
  
  Line l1
  Label keyLabel -text "Key:" -padx 10 -packFrame:padx 30
  Line l2
  CheckBox ctrl -text Control
  CheckBox meta -text Escape
  Entry key -text key -width 2
  ExtEntry keydef -entries ctrl meta key -count 1 -orient top

  CheckBox left -text Left
  CheckBox right -text Right
  CheckBox up -text Up
  CheckBox down -text Down
  Frame arrow -entries left right up down -orient top
  Line line -orient vertical
  Frame keys -entries keydef line arrow
  Radio which -text "Use: " -entries {
    "ordinary keys" "arrow keys"} \
      -packLabel:side left
  Line l3
  

  Entry external \
      -text "external commands"\
      -packEntry:side right\
      -packEntry:fill x -packFrame:fill x \
      -packEntry:expand 1 -packFrame:expand 1

  Entry string \
      -text "ordinary string" \
      -packEntry:fill x -packFrame:fill x \
      -packEntry:expand 1 -packFrame:expand 1
  
  ComboBox editor \
      -text "Editor commands"\
      -entries {
        "***** Movement *****"
        backward-char
        forward-char
        backward-word
        forward-word
        beginning-of-line
        end-of-line
        
        "***** Region *****"
        copy-region-as-kill
        exchange-point-and-mark
        set-mark-command
        yank
        copy-prev-word
        kill-region

        "***** Deletion *****"
        backward-delete-char
        backward-delete-word
        backward-kill-line
        delete-char
        delete-char-or-eof
        delete-char-or-list
        delete-char-or-list-or-eof
        delete-word
        kill-line
        kill-whole-line
        
        "***** Completion *****"
        complete-word
        complete-word-back
        complete-word-fwd
        complete-word-raw
        expand-glob
        expand-variables
        list-choices
        list-choices-raw
        list-glob
        list-or-eof
        
        "***** History *****"
        down-history
        expand-history
        expand-line
        history-search-backward
        history-search-forward
        i-search-back
        i-search-fwd
        insert-last-word
        toggle-literal-history
        up-history
        dabbrev-expand
        magic-space
        
        "***** Spelling *****"
        spell-line
        spell-word

        "***** Transpose / Case *****"
        transpose-chars
        transpose-gosling
        gosmacs-transpose-chars
        capitalize-word
        downcase-word
        upcase-word

        "***** Commands *****"
        clear-screen
        load-average
        redisplay
        run-fg-editor
        run-help
        which-command

        "***** TTY *****"
        tty-dsusp
        tty-flush-output
        tty-sigintr
        tty-sigquit
        tty-sigtsusp
        tty-start-output
        tty-stop-output

        "***** Prefix Commands *****"
        digit
        digit-argument
        prefix-meta
        quoted-insert
        sequence-lead-in
        universal-argument

        "***** VI commands *****"
        vi-add
        vi-add-at-eol
        vi-beginning-of-next-word
        vi-char-back
        vi-char-fwd
        vi-charto-back
        vi-charto-fwd
        vi-chg-case
        vi-chg-meta
        vi-chg-to-eol
        vi-cmd-mode
        vi-cmd-mode-complete
        vi-delmeta
        vi-delprev
        vi-endword
        vi-eword
        vi-insert
        vi-insert-at-bol
        vi-repeat-char-back
        vi-repeat-char-fwd
        vi-repeat-search-back
        vi-repeat-search-fwd
        vi-replace-char
        vi-replace-mode
        vi-search-back
        vi-search-fwd
        vi-substitute-char
        vi-substitute-line
        vi-undo
        vi-word-back
        vi-word-fwd
        vi-zero
        change-till-end-of-line
        change-case

        "***** Misc *****"
        end-of-file
        keyboard-quit
        newline
        normalize-command
        normalize-path
        overwrite-mode
        self-insert-command
        stuff-char
        undefined-key
      }

  ExtEntry bindings \
      -entries l1 keyLabel l2 keys which l3 external string editor\
      -count 1 \
      -orient top \
      -index keyLabel


  ################################ Help ################################
  Help changeEditor \
    "When you set the editor, you wish to use, tchs will forget all"\
    "it's bindings. This means that if you have bound any keys yourself"\
    "in your .tcshrc file, and then at the end source the output from"\
    "TDG, those keys will be forgot. So you should only change the"\
    "editor, if you don't have any keys bound, otherwise you should do"\
    "it yourself at the beginning of your .tcshrc file."
  Help mode "Tcsh bind most of it's keys like the editors emacs or"\
      "vi. If you are used to one of them, select this one, otherwise"\
      "you should select emacs, as it is the easiest one start with."

  Help keyLabel "This is just a label, where you can see what you've"\
      "selected."

  Help meta "This is the escape key, which is typed by pressing the"\
      "escape key, and then the key, which it is a prefix for."

  Help ctrl "This is the control key, which can be a modifier to most"\
      "keys. It can not be a modifier to the arrow keys, which is the"\
      "reason for the layout of this screen.\n\nNOTE:\nThe letter you"\
      "may insert here may not ne the letter on your keyboard. E.g. to"\
      "press Ctrl-j, you will insert the letter M in the entry. To see"\
      "which letter you have to insert, press C-v and you key, in a"\
      "shell, eg. C-vC-j will produce ^M, and in this case this \"M\""\
      "is the letter to insert."

  Help key "This is the letter you which to bind a command"\
      "to\n\nNOTE:\nThe letter you may insert here may not ne the"\
      "letter on your keyboard. E.g. to press Ctrl-j, you will insert"\
      "the letter M in the entry. To see which letter you have to"\
      "insert, press C-v and you key, in a shell, eg. C-vC-j will"\
      "produce ^M, and in this case this \"M\" is the letter to"\
      "insert."

  Help which "Here you select whether you want to define an ordinary key"\
      "or an arrow key. The reason for the distinction, is that in tcsh"\
      "you can not define a sequence, which include the arrow keys."

  Help external "Here you can type any external command you want. When"\
      "you press the key which this is bound to, the command is"\
      "executed at once."

  Help string "This string will be inserted on the command line, when you"\
      "type the key this is bound to."

  EntryHelp editor backward-delete-char \
      "Delete the character to the left of the cursor."
  EntryHelp editor backward-delete-word \
      "Delete from the beginning of the current word to the cursor.  Deleted"\
      "text is saved in the cut buffer."
  EntryHelp editor backward-kill-line \
      "Delete from the beginning of the line to the cursor. Deleted text"\
      "is saved in the cut buffer."
  EntryHelp editor capitalize-word \
      "Convert the character under the cursor to uppercase and move the"\
      "cursor to the end of the word."
  EntryHelp editor change-case \
      "Change the case of the character under the cursor and move the"\
      "cursor right one character. (vi only)"
  EntryHelp editor change-till-end-of-line \
      "Change text from the cursor position to the end of the line,"\
      "replacing it with new characters until ESC is typed. (vi only)"
  EntryHelp editor clear-screen \
      "Clear  the  screen, redrawing the current prompt and command line at the"\
      " top of the screen.  This is much quicker than  using the clear shell command."\
      "See also redisplay."
  EntryHelp editor complete-word \
      "Perform completion on the current word. Uses programmed"\
      "completions, if any are applicable. See also complete- word-raw."
  EntryHelp editor complete-word-back \
      "Like complete-word-fwd, but displays the possible completions in"\
      "reverse order."
  EntryHelp editor complete-word-fwd \
      "The current word is treated as a completion prefix. Successive"\
      "complete-word-fwd commands successively replace the current word"\
      "with each of the possible completions.  When the list of"\
      "completions is exhausted, the shell beeps and replaces the current"\
      "word with the original prefix. You can use complete-word-fwd and"\
      "complete-word-back to move back and forth in the list of"\
      "completions.  Uses programmed completions, if any are applicable."
  EntryHelp editor complete-word-raw \
      "Like complete-word, but ignores programmed completions."
  EntryHelp editor copy-prev-word \
      "Copy the previous word to the cursor position, including any"\
      "whitespace between the word and the cursor. See also"\
      "insert-last-word."
  EntryHelp editor copy-region-as-kill \
      "Copy the area between the mark and the cursor to the cut"\
      "buffer. See also kill-region and set-mark-command."
  EntryHelp editor delete-char \
      "Delete the character under the cursor."
  EntryHelp editor delete-char-or-eof \
      "Delete the character under the cursor or indicate end of file if"\
      "the current line is empty."
  EntryHelp editor delete-char-or-list \
      "Delete the character under the cursor or list completions if the"\
      "cursor is at the end of the line."
  EntryHelp editor delete-char-or-list-or-eof \
      "Delete the character under the cursor, list completions if the"\
      "cursor is at the end of the line, or indicate end of file if the"\
      "current line is empty."
  EntryHelp editor delete-word \
      "Delete the characters from the cursor to the end of the current"\
      "word. Deleted text is saved in the cut buffer."
  EntryHelp editor digit \
      "If a repeat count is currently being collected, add the digit to"\
      "the end of it. Otherwise, enter the digit into the command line."
  EntryHelp editor digit-argument \
      "Begin collecting repeat count for the following command."\
      "Subsequent digit comands are added to the repeat count."
  EntryHelp editor down-history \
      "Recall the next history line into the edit buffer. When repeated,"\
      "continues down through the history list, stopping at the end of"\
      "the list. See also up-history."
  EntryHelp editor downcase-word \
      "Convert characters from the cursor to the end of the current word"\
      "to lowercase. See also upcase-word."
  EntryHelp editor end-of-file \
      "Indicate end of file to the shell."
  EntryHelp editor end-of-line \
      "Move the cursor to the end of the line."
  EntryHelp editor exchange-point-and-mark \
      "Exchange the cursor (point) and mark positions. This is useful if"\
      "you've forgotten where the mark is. A second"\
      "exchange-point-and-mark command returns the cursor to its original"\
      "position. See also set-mark-command."
  EntryHelp editor expand-glob \
      "Expand the filename pattern to the left of the cursor, replacing it"\
      "with the matching filenames. See also list-glob."
  EntryHelp editor expand-history \
      "Expand history references in the current word. History references"\
      "beginning with !\# are not expanded."
  EntryHelp editor expand-line \
      "Expand all history references in a command line, including"\
      "references beginning with !\#. See also magic-space and"\
      "toggle-literal-history."
  EntryHelp editor expand-variables \
      "Expand variable references in the current word."
  EntryHelp editor gosmacs-transpose-chars \
      "Exchange the two characters the the left of the cursor (like"\
      "Gosling emacs). See also transpose-chars."
  EntryHelp editor history-search-backward \
      "Search backward through the history list using the current contents"\
      "of the edit buffer up to the cursor as a search string (which may"\
      "be a filename pattern).  The command retrieves the previous"\
      "command beginning with that string.  (If the command buffer is"\
      "empty, all commands match and history-search-backward simply"\
      "retrieves the previous command like up-history.) If the first"\
      "command retrieved is not the one you wanted, repeat"\
      "history-search-backward until you find the right one. If you go"\
      "too far, history-search-fwd searches in the other direction."\
      "Identical matches are skipped. history-search-backward does not"\
      "wrap around when the beginning of the history list is reached."
  EntryHelp editor history-search-forward \
      "Like history-search-backward, but searches forward through the"\
      "history list. history-search-backward does not wrap around when"\
      "the end of the history list is reached."
  EntryHelp editor insert-last-word \
      "Insert the final word of the previous command at the cursor"\
      "position. See also copy-prev-word."
  EntryHelp editor i-search-back \
      "Perform an emacs-style incremental search. Presents bck: as a"\
      "prompt and waits for you to type a search string.  As you type"\
      "successive characters, the command editor searches back through"\
      "your history list for commands matching the current search string"\
      "and successively copies them into the edit buffer. To back up"\
      "through the commands retrieved, or if you make a typing mistake,"\
      "delete the last character from the search string and the shell"\
      "returns the previously retrieved command into the edit"\
      "buffer. Type ESC to terminate the search and leave the current"\
      "line in the edit buffer. Hit RETURN to execute the command.  For"\
      "each command retrieved, the cursor is positioned at the end of the"\
      "matching string within the command.  Type CTRL-W to copy the rest"\
      "of the word under the cursor to the end of the search string.  If"\
      "no command matches the search string when you type a new"\
      "character, the shell beeps. Typing CTRL-G returns to the previous"\
      "successful search. CTRL-G aborts the search if the previous"\
      "character resulted in a successful search."
  EntryHelp editor i-search-fwd \
      "Like i-search-back, but searches forward."
  EntryHelp editor keyboard-quit \
      "Clear the entire command line."
  EntryHelp editor kill-line \
      "Delete from the cursor to the end of the line.  Deleted text is"\
      "saved in the cut buffer. See also backward-kill- line."
  EntryHelp editor kill-region \
      "Delete the characters between the mark and the cursor.  If the"\
      "region isn't what you thought it was, issue a yank command to put"\
      "the deleted text back.  Deleted text is saved in the cut"\
      "buffer. See also copy-region-as-kill, set-mark-command, and"\
      "exchange-point-and-mark."
  EntryHelp editor kill-whole-line \
      "Delete the entire line. Deleted text is saved in the cut buffer."
  EntryHelp editor list-choices \
      "List possible completions for the current word. Uses programmed"\
      "completions, if any are applicable. See also list-choices-raw."
  EntryHelp editor list-choices-raw \
      "List possible completions for the current word, ignoring programmed"\
      "completions. See also list-choices."
  EntryHelp editor list-glob \
      "List filename wildcard matches for the current word. See also"\
      "expand-glob."
  EntryHelp editor list-or-eof \
      "List possible completions for the current word or indicate end of"\
      "file if the line is empty."
  EntryHelp editor load-average \
      "Display the system load average and current process status."
  EntryHelp editor magic-space \
      "Expand history references in the current word, then add a"\
      "space. (Acts similar to expand-history, so references beginning"\
      "with !\# are not expanded.) If you bind magic-space to SPACE, then"\
      "all history references are expanded as you type successive words"\
      "of command lines. See also expand-history."
  EntryHelp editor newline \
      "Execute the current command (the command in the edit buffer)."
  EntryHelp editor normalize-command \
      "Looks for the current word as a command in your search path and"\
      "replaces it with the command's full pathname.  If the word is an"\
      "alias, the word is replaced by the alias definition. If the word"\
      "is a builtin command, the word remains unchanged. If the word"\
      "isn't a command, an alias, or a builtin, the shell beeps."
  EntryHelp editor normalize-path \
      "Expand the current word as a pathname, eliminating leading . and"\
      ".. components as if the symlinks shell variable were set to"\
      "expand."
  EntryHelp editor overwrite-mode (emacs only?) \
      "Switch from insert to overwrite mode or vice versa.  In insert"\
      "mode, new characters are inserted into the command line at the"\
      "cursor position.  In overwrite mode, new characters overwrite"\
      "characters under the cursor. See also self-insert-command."
  EntryHelp editor prefix-meta \
      "Turn on the high bit of the next character you type."
  EntryHelp editor quoted-insert \
      "Add the next character you type to the command line literally"\
      "without interpretation, even if the character is otherwise"\
      "special. For instance, to enter a literal TAB into the command"\
      "line instead of having it trigger filename completion, precede it"\
      "with quoted-insert."
  EntryHelp editor redisplay \
      "Redisplay the command line. This is useful if another program blats"\
      "output on the screen and messes it up while you're typing a"\
      "command. See also clear-screen."
  EntryHelp editor run-fg-editor \
      "Look for a stopped editor job and restart it.  Editor jobs are"\
      "identified by looking at the values of the EDITOR and VISUAL"\
      "environment variables. If neither is set, jobs beginning with ed"\
      "or vi are considered editor jobs.  Restarting an editor is a job"\
      "control operation you're likely to do often. The default binding"\
      "is ESC CTRL-Z, but you can bind it to CTRL-Z to make it easier to"\
      "use.  This way you can restart an editor using the same key you"\
      "use to stop it."
  EntryHelp editor run-help \
      "Look for documentation on the current command and display it.  This"\
      "is intended for display of short files since the output is not run"\
      "through a pager. The shell looks for help files in directories"\
      "named in the HPATH environment variable. For a command xyz, files"\
      "named xyz.help, xyz.1, xyz.6, or xyz.8 are considered help files."
  EntryHelp editor self-insert-command \
      "Add a character as itself to the current command, or replace the"\
      "character under the cursor if in overwrite mode. See also"\
      "overwrite-mode."
  EntryHelp editor sequence-lead-in \
      "You don't actually bind this command to a key sequence.  When you"\
      "use bindkey to display key bindings and a character is indicated"\
      "as bound to sequence-lead-in, it means that one or more"\
      "multiple-character sequences beginning with the character have"\
      "been bound to a command."
  EntryHelp editor set-mark-command \
      "Set a mark at the cursor position. Some keyboards may not generate"\
      "the proper character for the default binding (CTRL-@, a null"\
      "character); in that case you'll need to rebind the command to"\
      "something else. See also exchange-point-and-mark."
  EntryHelp editor spell-line \
      "For each word of the current line, attempts to correct the word as"\
      "for spell-word, except for words beginning with !, ., \, ^, -, or"\
      "%, or containing filename pattern characters."
  EntryHelp editor spell-word \
      "Correct the spelling of the current word. The first word of a line"\
      "is corrected as a command name and subsequent words are corrected"\
      "as filenames. If the word appears to be a pathname, correction is"\
      "attempted for each component of the pathname."
  EntryHelp editor stuff-char \
      "Send the character to the terminal in cooked mode."
  EntryHelp editor toggle-literal-history \
      "Toggle between the literal and lexical representations of the"\
      "current history line. This affects all commands that retrieve"\
      "lines from the history list into the edit buffer, such as"\
      "up-history. The literal representation of a line is the line just"\
      "as you typed it, with history references unexpanded.  The lexical"\
      "representation of a line has history references expanded and a"\
      "space between successive words. See also expand-history."
  EntryHelp editor transpose-chars \
      "Exchange the character to the left of the cursor with the character"\
      "under the cursor. See also gosmacs-transpose-chars."
  EntryHelp editor transpose-gosling \
      "Same as gosmacs-transpose-chars."
  EntryHelp editor tty-dsusp \
      "Terminal delayed-suspend character. Generally the dsusp"\
      "character. See the section ``Terminal Control Charac- ters''"\
      "below."
  EntryHelp editor tty-flush-output \
      "Terminal flush-output character.  Generally the oflush"\
      "character. See the section ``Terminal Control Characters'' below."
  EntryHelp editor tty-sigintr \
      "Terminal interrupt character. Generally the intr character. See the"\
      "section ``Terminal Control Characters'' below."
  EntryHelp editor tty-sigquit \
      "Terminal quit character. Generally the quit character.  See the"\
      "section ``Terminal Control Characters'' below."
  EntryHelp editor tty-sigtsusp \
      "Terminal suspend character. Generally the susp character.  See the"\
      "section ``Terminal Control Characters'' below."
  EntryHelp editor tty-start-output \
      "Terminal allow-output character.  Generally the start character."\
      "See the section ``Terminal Control Characters'' below."
  EntryHelp editor tty-stop-output \
      "Terminal disallow-output character. Generally the stop character."\
      "See the section ``Terminal Control Characters''."
  EntryHelp editor undefined-key \
      "This command indicates that a key is ignored, i.e., the key is"\
      "unbound. When you type an unbound key, the shell beeps. Normally,"\
      "you don't actually bind this command to a key, you use bindkey -r"\
      "instead."
  EntryHelp editor universal-argument \
      "emacs universal argument. Repeats the following command four"\
      "times. If specified twice, repeats the following command 16 times."
  EntryHelp editor up-history \
      "Recall the previous history line into the edit buffer.  When"\
      "repeated, continues up through the history list, stopping at the"\
      "beginning of the list. See also down-history."
  EntryHelp editor upcase-word \
      "Convert characters from the cursor to the end of the current word"\
      "to uppercase. See also downcase-word and capitalize-word."
  EntryHelp editor vi-add (vi only) \
      "Enter vi insert mode, allowing text entry to the right of the"\
      "cursor."
  EntryHelp editor vi-add-at-eol (vi only) \
      "Enter vi insert mode, allowing text entry at the end of the line."
  EntryHelp editor vi-beginning-of-next-word (vi only) \
      "Move the cursor to the beginning of the next space- or"\
      "punctuation-delimited word. See also vi-word-fwd."
  EntryHelp editor vi-char-back (vi only) \
      "Move the cursor backward to the previous instance of the next"\
      "character you type."
  EntryHelp editor vi-char-fwd (vi only) \
      "Move the cursor forward to the next instance of the next character"\
      "you type."
  EntryHelp editor vi-charto-back (vi only) \
      "Move the cursor backward to the right of the previous instance of"\
      "the next character you type."
  EntryHelp editor vi-charto-fwd (vi only) \
      "Move the cursor forward to the left of the next instance of the"\
      "next character you type."
  EntryHelp editor vi-chg-case (vi only) \
      "Change the case of the character under the cursor and move the"\
      "cursor right one character."
  EntryHelp editor vi-chg-meta (vi only) \
      "This command is the prefix in vi command mode for change-text"\
      "commands. When followed by a cursor motion command, enters insert"\
      "mode so you can change the text from the cursor position to the"\
      "text where the cursor motion command would place the cursor. For"\
      "instance, use cw to change a word, c\$ to change the rest of the"\
      "line, and c0 to change everything from the beginning of the line"\
      "to the cursor."
  EntryHelp editor vi-chg-to-eol (vi only) \
      "Same as change-till-end-of-line."
  EntryHelp editor vi-cmd-mode (vi only) \
      "Enter vi command mode. The bindings from the alternative key map"\
      "are used in command mode."
  EntryHelp editor vi-cmd-mode-complete (vi only) \
      "Like complete-word but works in vi command mode."
  EntryHelp editor vi-delprev (vi only) \
      "Backspace over the previous character in vi insert mode."\
      "Backspaces only when the cursor is at the end of the characters"\
      "added since insert mode was entered, and backspaces only to the"\
      "beginning of those characters."
  EntryHelp editor vi-delmeta (vi only) \
      "This command is the prefix in vi command mode for delete-text"\
      "commands. When followed by a cursor motion command, deletes text"\
      "from the cursor position to where the cursor motion command would"\
      "place the cursor. For instance, use dw to delete a word, d\$ to"\
      "delete the rest of the line, and d0 to delete backward to the"\
      "beginning of the line."
  EntryHelp editor vi-endword (vi only) \
      "Move the cursor to the end of the current space-delimited word. See"\
      "also vi-eword."
  EntryHelp editor vi-eword (vi only) \
      "Move the cursor to the end of the current space- or"\
      "punctuation-delimited word. See also vi-endword."
  EntryHelp editor vi-insert (vi only) \
      "Enter vi insert mode, allowing text entry to the left of cursor."
  EntryHelp editor vi-insert-at-bol (vi only) \
      "Enter vi insert mode, allowing text entry at the beginning of the"\
      "line."
  EntryHelp editor vi-repeat-char-back (vi only) \
      "Repeat the current character search in the opposite search"\
      "direction.  That is, it repeats vi-char-back as vi-char-fwd and"\
      "vi-char-fwd as vi-char-back."
  EntryHelp editor vi-repeat-char-fwd (vi only) \
      "Repeat the current character search in the same search direction."\
      "That is, it repeats vi-char-back as vi-char-back and vi-char-fwd"\
      "as vi-char-fwd."
  EntryHelp editor vi-repeat-search-back (vi only) \
      "Like vi-repeat-search-fwd, but in the opposite direction."
  EntryHelp editor vi-repeat-search-fwd (vi only) \
      "Repeat the current search in the same search direction.  If you"\
      "begin a backward search with vi-search-back, then"\
      "vi-repeat-search-back does another backward search. If you begin a"\
      "forward search with vi-search-fwd, then vi-repeat-search-back does"\
      "another forward search.  vi-repeat-search-fwd and"\
      "vi-repeat-search-back might better be named as vi-repeat-search"\
      "and vi-repeat-search-reverse or something like that."
  EntryHelp editor vi-replace-char (vi only) \
      "Replace the character under the cursor with the next character you"\
      "type.  Advances the cursor, unlike vi itself."
  EntryHelp editor vi-replace-mode (vi only) \
      "Enter vi character replacement mode, where characters you type"\
      "replace successive characters in the command line."
  EntryHelp editor vi-search-back (vi only) \
      "Search the history list backward.  When you use vi-search-back, the"\
      "shell prompts with a ? character.  Type a search string (which may"\
      "be a filename pattern) and hit RETURN. The command retrieves the"\
      "previous command containing with that string, or beeps if there is"\
      "no match in the history list. If the command retrieved is not the"\
      "one you wanted, repeat the search until you find the one you want"\
      "using vi-repeat-search-fwd (no, that's not a typo, see the"\
      "description of vi-repeat-search-fwd). Hit RETURN to terminate the"\
      "search and leave the most recently retrieved command in the edit"\
      "buffer. Hit ESC to execute the currently retrieved command."\
      "vi-search-back and vi-repeat-search-back wrap around when the"\
      "beginning of the history list is reached."
  EntryHelp editor vi-search-fwd (vi only) \
      "Like vi-search-back, but prompts with a / character and searches"\
      "forward."
  EntryHelp editor vi-substitute-char (vi only) \
      "Enter insert mode to replace the character under the cursor."
  EntryHelp editor vi-substitute-line (vi only) \
      "Enter insert mode to replace the entire line."
  EntryHelp editor vi-word-back (vi only) \
      "Move the cursor to the previous word. See also backward-word."
  EntryHelp editor vi-word-fwd (vi only) \
      "Move the cursor to the next word. See also"\
      "vi-beginning-of-next-word."
  EntryHelp editor vi-undo (vi only) \
      "Undo the last change. vi-undo is unreliable, unfortunately."
  EntryHelp editor vi-zero (vi only) \
      "Move the cursor to the beginning of the line. See also"\
      "beginning-of-line, which in vi mode moves the cursor to the first"\
      "non-whitespace character."
  EntryHelp editor which-command \
      "Runs which for the first word of the current line."
  EntryHelp editor yank \
      "Yank the contents of the cut buffer into the command line at the"\
      "cursor position. The cut buffer contents remain unchanged."

  ############################### Change ###############################
  Change {
    ### disable mode, if not changeEditor
    eval [pick $changeEditor Enable Disable] mode
    ### allow only one char in the key
    if {$changeElm == "key" && [string length $key] > 1} {
      set key [string index $key [expr [string length $key]-1]]
    }

    ### disable other input elements if one either external or string
    ### is active
    if {$changeElm == "external" || $changeElm == "string"} {
      Enable string editor external
      if {$external != ""} {
        Disable string editor
      } elseif {$string != ""} {
        Disable external editor
      }
    }

    ### update the radio property for the four arrows
    if {[lsearch {left right up down} $changeElm] != -1 &&
        [set $changeElm] == 1} {
      foreach elm {up down left right} {
        if {$elm != $changeElm} {
          set $elm 0
        }
      }
    }

    ### update the label
    if {[lsearch {left right up down which ctrl meta key} $changeElm] != -1} {
            set keyLabel ""
      if {$which(index) == 0} {
        Disable arrow
        Enable keydef
        forevery keydef {
          if {$ctrl} {
            append keyLabel "CTRL-"
          }
          if {$meta} {
            append keyLabel "ESC-"
          }
          append keyLabel "$key "
        }
      } else {
        Enable arrow
        Disable keydef
        foreach elm {left right up down} {
          if {[set $elm] == 1} {
            set keyLabel [capitalize $elm]
            break
          }
        }
      }
    }

    ### **** --- **** element may not be selected in the editor listbox
    if {$changeElm == "editor" && [string index $editor 0] == "*"} {
      set editor ""
    }
  }

  ################################ Init ################################
  Init {
    if {!$loadingExports && $changeElm == "bindings"} {
      AddTuple keydef
    }
  }
  ############################## Page End ##############################
  PageEnd {
    forevery bindings {

      if {$which(index) == 0} {
        set str ""
        forevery keydef {
          if {$meta} {
            append str "ESC-"
          }
          if {$ctrl} {
            append str CTRL-
          }
          if {$key == "" && $str != ""} {
            error "No key given, though either Ctrl or ESC were given"
          } else {
            append str $key
          }
        }
      } else {
        foreach elm {left right up down} {
          if {[set $elm]} {
            set str "$elm"
          }
        }
      }
      if {$str == ""} continue
      
      if {$str != ""  && $external == "" && $string == "" && $editor == ""} {
        error "Binding for key \"$str\" need either an external command"\
            "a string or an editor command."
      }
      if {$external == "" && $string == "" && $editor == ""} {
        error "No action given for key \"$str\""
      }
    }
  }
  
  ################################ Save ################################
  Save {
    if {$changeEditor} {
      print "bindkey [pick {$mode(name) == {emacs}} -e -v]"
    }
    forevery bindings {
      
      if {$which(index) == 0} {
        set str ""
        forevery keydef {
          if {$meta} {
            append str "^\["
          }
          if {$ctrl} {
            append str ^
          }
          append str $key
        }
      } else {
        foreach elm {left right up down} {
          if {[set $elm]} {
            set str "-k $elm"
          }
        }
      }
      if {$str == ""} continue
      if {$external != ""} {
        print "bindkey -c $str \"$external\""
      } elseif {$string != ""} {
        print "bindkey -s $str \"$string\""
      } else {
        print "bindkey $str $editor"
      }
    }
  }
}
