Customizing the Keyboard

The command line editing and history is provided by the libtecla library. This library is configurable.

  • Editing mode can be changed: (emacs or vi) [default: emacs]

  • Keyboard character sequence to command bindings

The libtecla configuration file for yangcli-pro and yp-shell is called $HOME/.teclarc. If this file is found then the settings will be applied when the program starts. Any number of key binding lines can be present in this file.

Changing the Editing Mode

Key bindings for the "emacs" or "vi" editor can be selected. The default mode is "emacs". To change the mode to "vi", use the following line in the .teclarc file:

edit-mode vi

Changing Key Bindings

The key bindings within an edit mode (emacs or vi) can be changed with the 'bind' command.

Example .teclarc:

bind C-w backward-delete-word

This command would change the function bound to the Control-w key sequence. The default mapping is 'kill-region' and this 'bind' command will change the binding for Control-w to 'backward-delete-word'.

Refer to the tecla documentation for details on all the key bindings available and default key bindings.

The following sections are from the libtecla documentation, and describe the key bindings available, and the default key bindings used in yangcli-pro.

Available Key Bindings

user-interrupt           -  Send a SIGINT signal to the
                            parent process.
abort                    -  Send a SIGABRT signal to the
                            parent process.
suspend                  -  Suspend the parent process.
stop-output              -  Pause terminal output.
start-output             -  Resume paused terminal output.
literal-next             -  Arrange for the next character
                            to be treated as a normal
                            character. This allows control
                            characters to be entered.
cursor-right             -  Move the cursor one character
                            right.
cursor-left              -  Move the cursor one character
                            left.
insert-mode              -  Toggle between insert mode and
                            overwrite mode.
beginning-of-line        -  Move the cursor to the
                            beginning of the line.
end-of-line              -  Move the cursor to the end of
                            the line.
delete-line              -  Delete the contents of the
                            current line.
kill-line                -  Delete everything that follows
                            the cursor.
backward-kill-line       -  Delete all characters between
                            the cursor and the start of the
                            line.
forward-word             -  Move to the end of the word
                            which follows the cursor.
forward-to-word          -  Move the cursor to the start of
                            the word that follows the
                            cursor.
backward-word            -  Move to the start of the word
                            which precedes the cursor.
goto-column              -  Move the cursor to the
                            1-relative column in the line
                            specified by any preceding
                            digit-argument sequences (see
                            ENTERING REPEAT COUNTS below).
find-parenthesis         -  If the cursor is currently
                            over a parenthesis character,
                            move it to the matching
                            parenthesis character. If not
                            over a parenthesis character
                            move right to the next close
                            parenthesis.
forward-delete-char      -  Delete the character under the
                            cursor.
backward-delete-char     -  Delete the character which
                            precedes the cursor.
list-or-eof              -  This is intended for binding
                            to ^D. When invoked when the
                            cursor is within the line it
                            displays all possible
                            completions then redisplays
                            the line unchanged. When
                            invoked on an empty line, it
                            signals end-of-input (EOF) to
                            the caller of gl_get_line().
del-char-or-list-or-eof  -  This is intended for binding
                            to ^D. When invoked when the
                            cursor is within the line it
                            invokes forward-delete-char.
                            When invoked at the end of the
                            line it displays all possible
                            completions then redisplays
                            the line unchanged. When
                            invoked on an empty line, it
                            signals end-of-input (EOF) to
                            the caller of gl_get_line().
forward-delete-word      -  Delete the word which follows
                            the cursor.
backward-delete-word     -  Delete the word which precedes
                            the cursor.
upcase-word              -  Convert all of the characters
                            of the word which follows the
                            cursor, to upper case.
downcase-word            -  Convert all of the characters
                            of the word which follows the
                            cursor, to lower case.
capitalize-word          -  Capitalize the word which
                            follows the cursor.
change-case              -  If the next character is upper
                            case, toggle it to lower case
                            and vice versa.
redisplay                -  Redisplay the line.
clear-screen             -  Clear the terminal, then
                            redisplay the current line.
transpose-chars          -  Swap the character under the
                            cursor with the character just
                            before the cursor.
set-mark                 -  Set a mark at the position of
                            the cursor.
exchange-point-and-mark  -  Move the cursor to the last
                            mark that was set, and move
                            the mark to where the cursor
                            used to be.
kill-region              -  Delete the characters that lie
                            between the last mark that was
                            set, and the cursor.
copy-region-as-kill      -  Copy the text between the mark
                            and the cursor to the cut
                            buffer, without deleting the
                            original text.
yank                     -  Insert the text that was last
                            deleted, just before the
                            current position of the cursor.
append-yank              -  Paste the current contents of
                            the cut buffer, after the
                            cursor.
up-history               -  Recall the next oldest line
                            that was entered. Note that
                            in vi mode you are left in
                            command mode.
down-history             -  Recall the next most recent
                            line that was entered. If no
                            history recall session is
                            currently active, the next
                            line from a previous recall
                            session is recalled. Note that
                            in vi mode you are left in
                            command mode.
history-search-backward  -  Recall the next oldest line
                            who's prefix matches the string
                            which currently precedes the
                            cursor (in vi command-mode the
                            character under the cursor is
                            also included in the search
                            string).  Note that in vi mode
                            you are left in command mode.
history-search-forward   -  Recall the next newest line
                            who's prefix matches the string
                            which currently precedes the
                            cursor (in vi command-mode the
                            character under the cursor is
                            also included in the search
                            string).  Note that in vi mode
                            you are left in command mode.
history-re-search-backward -Recall the next oldest line
                            who's prefix matches that
                            established by the last
                            invocation of either
                            history-search-forward or
                            history-search-backward.
history-re-search-forward - Recall the next newest line
                            who's prefix matches that
                            established by the last
                            invocation of either
                            history-search-forward or
                            history-search-backward.
complete-word            -  Attempt to complete the
                            incomplete word which
                            precedes the cursor. Unless
                            the host program has customized
                            word completion, filename
                            completion is attempted. In vi
                            commmand mode the character
                            under the cursor is also
                            included in the word being
                            completed, and you are left in
                            vi insert mode.
expand-filename          -  Within the command line, expand
                            wild cards, tilde expressions
                            and dollar expressions in the
                            filename which immediately
                            precedes the cursor. In vi
                            commmand mode the character
                            under the cursor is also
                            included in the filename being
                            expanded, and you are left in
                            vi insert mode.
list-glob                -  List any filenames which match
                            the wild-card, tilde and dollar
                            expressions in the filename
                            which immediately precedes the
                            cursor, then redraw the input
                            line unchanged.
list-history             -  Display the contents of the
                            history list for the current
                            history group. If a repeat
                            count of > 1 is specified,
                            only that many of the most
                            recent lines are displayed.
                            See the "ENTERING REPEAT
                            COUNTS" section.
read-from-file           -  Temporarily switch to reading
                            input from the file who's
                            name precedes the cursor.
read-init-files          -  Re-read teclarc configuration
                            files.
beginning-of-history     -  Move to the oldest line in the
                            history list. Note that in vi
                            mode you are left in command
                            mode.
end-of-history           -  Move to the newest line in the
                            history list (ie. the current
                            line). Note that in vi mode
                            this leaves you in command
                            mode.
digit-argument           -  Enter a repeat count for the
                            next key-binding function.
                            For details, see the ENTERING
                            REPEAT COUNTS section.
newline                  -  Terminate and return the
                            current contents of the
                            line, after appending a
                            newline character. The newline
                            character is normally '\n',
                            but will be the first
                            character of the key-sequence
                            that invoked the newline
                            action, if this happens to be
                            a printable character. If the
                            action was invoked by the
                            '\n' newline character or the
                            '\r' carriage return
                            character, the line is
                            appended to the history
                            buffer.
repeat-history           -  Return the line that is being
                            edited, then arrange for the
                            next most recent entry in the
                            history buffer to be recalled
                            when Tecla is next called.
                            Repeatedly invoking this
                            action causes successive
                            historical input lines to be
                            re-executed. Note that this
                            action is equivalent to the
                            'Operate' action in ksh.
ring-bell                -  Ring the terminal bell, unless
                            the bell has been silenced via
                            the nobeep configuration
                            option (see the THE TECLA
                            CONFIGURATION FILE section).
forward-copy-char        -  Copy the next character into
                            the cut buffer (NB. use repeat
                            counts to copy more than one).
backward-copy-char       -  Copy the previous character
                            into the cut buffer.
forward-copy-word        -  Copy the next word into the cut
                            buffer.
backward-copy-word       -  Copy the previous word into the
                            cut buffer.
forward-find-char        -  Move the cursor to the next
                            occurrence of the next
                            character that you type.
backward-find-char       -  Move the cursor to the last
                            occurrence of the next
                            character that you type.
forward-to-char          -  Move the cursor to the
                            character just before the next
                            occurrence of the next
                            character that the user types.
backward-to-char         -  Move the cursor to the
                            character just after the last
                            occurrence before the cursor
                            of the next character that the
                            user types.
repeat-find-char         -  Repeat the last
                            backward-find-char,
                            forward-find-char,
                            backward-to-char or
                            forward-to-char.
invert-refind-char       -  Repeat the last
                            backward-find-char,
                            forward-find-char,
                            backward-to-char, or
                            forward-to-char in the
                            opposite direction.
delete-to-column         -  Delete the characters from the
                            cursor up to the column that
                            is specified by the repeat
                            count.
delete-to-parenthesis    -  Delete the characters from the
                            cursor up to and including
                            the matching parenthesis, or
                            next close parenthesis.
forward-delete-find      -  Delete the characters from the
                            cursor up to and including the
                            following occurence of the
                            next character typed.
backward-delete-find     -  Delete the characters from the
                            cursor up to and including the
                            preceding occurence of the
                            next character typed.
forward-delete-to        -  Delete the characters from the
                            cursor up to, but not
                            including, the following
                            occurence of the next
                            character typed.
backward-delete-to       -  Delete the characters from the
                            cursor up to, but not
                            including, the preceding
                            occurence of the next
                            character typed.
delete-refind            -  Repeat the last *-delete-find
                            or *-delete-to action.
delete-invert-refind     -  Repeat the last *-delete-find
                            or *-delete-to action, in the
                            opposite direction.
copy-to-column           -  Copy the characters from the
                            cursor up to the column that
                            is specified by the repeat
                            count, into the cut buffer.
copy-to-parenthesis      -  Copy the characters from the
                            cursor up to and including
                            the matching parenthesis, or
                            next close parenthesis, into
                            the cut buffer.
forward-copy-find        -  Copy the characters from the
                            cursor up to and including the
                            following occurence of the
                            next character typed, into the
                            cut buffer.
backward-copy-find       -  Copy the characters from the
                            cursor up to and including the
                            preceding occurence of the
                            next character typed, into the
                            cut buffer.
forward-copy-to          -  Copy the characters from the
                            cursor up to, but not
                            including, the following
                            occurence of the next
                            character typed, into the cut
                            buffer.
backward-copy-to         -  Copy the characters from the
                            cursor up to, but not
                            including, the preceding
                            occurence of the next
                            character typed, into the cut
                            buffer.
copy-refind              -  Repeat the last *-copy-find
                            or *-copy-to action.
copy-invert-refind       -  Repeat the last *-copy-find
                            or *-copy-to action, in the
                            opposite direction.
vi-mode                  -  Switch to vi mode from emacs
                            mode.
emacs-mode               -  Switch to emacs mode from vi
                            mode.
vi-insert                -  From vi command mode, switch to
                            insert mode.
vi-overwrite             -  From vi command mode, switch to
                            overwrite mode.
vi-insert-at-bol         -  From vi command mode, move the
                            cursor to the start of the line
                            and switch to insert mode.
vi-append-at-eol         -  From vi command mode, move the
                            cursor to the end of the line
                            and switch to append mode.
vi-append                -  From vi command mode, move the
                            cursor one position right, and
                            switch to insert mode.
vi-replace-char          -  From vi command mode, replace
                            the character under the cursor
                            with the the next character
                            entered.
vi-forward-change-char   -  From vi command mode, delete
                            the next character then enter
                            insert mode.
vi-backward-change-char  -  From vi command mode, delete
                            the preceding character then
                            enter insert mode.
vi-forward-change-word   -  From vi command mode, delete
                            the next word then enter
                            insert mode.
vi-backward-change-word  -  From vi command mode, delete
                            the preceding word then
                            enter insert mode.
vi-change-rest-of-line   -  From vi command mode, delete
                            from the cursor to the end of
                            the line, then enter insert
                            mode.
vi-change-line           -  From vi command mode, delete
                            the current line, then enter
                            insert mode.
vi-change-to-bol         -  From vi command mode, delete
                            all characters between the
                            cursor and the beginning of
                            the line, then enter insert
                            mode.
vi-change-to-column      -  From vi command mode, delete
                            the characters from the cursor
                            up to the column that is
                            specified by the repeat count,
                            then enter insert mode.
vi-change-to-parenthesis -  Delete the characters from the
                            cursor up to and including
                            the matching parenthesis, or
                            next close parenthesis, then
                            enter vi insert mode.
vi-forward-change-find   -  From vi command mode, delete
                            the characters from the
                            cursor up to and including the
                            following occurence of the
                            next character typed, then
                            enter insert mode.
vi-backward-change-find  -  From vi command mode, delete
                            the characters from the
                            cursor up to and including the
                            preceding occurence of the
                            next character typed, then
                            enter insert mode.
vi-forward-change-to     -  From vi command mode, delete
                            the characters from the
                            cursor up to, but not
                            including, the following
                            occurence of the next
                            character typed, then enter
                            insert mode.
vi-backward-change-to    -  From vi command mode, delete
                            the characters from the
                            cursor up to, but not
                            including, the preceding
                            occurence of the next
                            character typed, then enter
                            insert mode.
vi-change-refind         -  Repeat the last
                            vi-*-change-find or
                            vi-*-change-to action.
vi-change-invert-refind  -  Repeat the last
                            vi-*-change-find or
                            vi-*-change-to action, in the
                            opposite direction.
vi-undo                  -  In vi mode, undo the last
                            editing operation.
vi-repeat-change         -  In vi command mode, repeat the
                            last command that modified the
                            line.

Default Key Bindings for Emacs

The cursor keys are refered to by name, as follows. This is necessary because different types of terminals generate different key sequences when their cursor keys are pressed.

right  ->   cursor-right
left   ->   cursor-left
up     ->   up-history
down   ->   down-history

The remaining bindings don't depend on the terminal setttings.

^F     ->   cursor-right
^B     ->   cursor-left
M-i    ->   insert-mode
^A     ->   beginning-of-line
^E     ->   end-of-line
^U     ->   delete-line
^K     ->   kill-line
M-f    ->   forward-word
M-b    ->   backward-word
^D     ->   del-char-or-list-or-eof
^H     ->   backward-delete-char
^?     ->   backward-delete-char
M-d    ->   forward-delete-word
M-^H   ->   backward-delete-word
M-^?   ->   backward-delete-word
M-u    ->   upcase-word
M-l    ->   downcase-word
M-c    ->   capitalize-word
^R     ->   redisplay
^L     ->   clear-screen
^T     ->   transpose-chars
^@     ->   set-mark
^X^X   ->   exchange-point-and-mark
^W     ->   kill-region
M-w    ->   copy-region-as-kill
^Y     ->   yank
^P     ->   up-history
^N     ->   down-history
M-p    ->   history-search-backward
M-n    ->   history-search-forward
^I     ->   complete-word
^X*    ->   expand-filename
^X^F   ->   read-from-file
^X^R   ->   read-init-files
^Xg    ->   list-glob
^Xh    ->   list-history
M-<    ->   beginning-of-history
M->    ->   end-of-history
\n     ->   newline
\r     ->   newline
M-o    ->   repeat-history
M-^V   ->   vi-mode
M-0, M-1, ... M-9  ->  digit-argument