tecla, teclarc - User interface provided by the tecla library.
This man page describes the command-line editing features that are available to users of programs that read keyboard input via the tecla library. Users of the tcsh shell will find the default key bindings very familiar. Users of the bash shell will also find it quite familiar, but with a few minor differences, most notably in how forward and backward searches through the list of historical commands are performed. There are two major editing modes, one with emacs-like key bindings and another with vi-like key bindings. By default emacs mode is enabled, but vi(1) mode can alternatively be selected via the user's configuration file. This file can also be used to change the bindings of individual keys to suit the user's preferences. By default, tab completion is provided. If the application hasn't reconfigured this to complete other types of symbols, then tab completion completes file names.
In the rest of this man page, and also in all tecla configuration files, key sequences are expressed as follows.
^A or C-a
E or M-
up
down
left
right
a
By default, tecla looks for a file called .teclarc in your home directory (ie. ~/.teclarc). If it finds this file, it reads it, interpreting each line as defining a new key binding or an editing configuration option. Since the emacs key-bindings are installed by default, if you want to use the non-default vi editing mode, the most important item to go in this file is the following line:
edit-mode vi
This will re-configure the default bindings for vi-mode. The complete set of arguments that this command accepts are:
vi
emacs
none
To prevent the terminal bell from being rung, such as when an unrecognized control-sequence is typed, place the following line in the configuration file:
nobeep
An example of a key binding line in the configuration file is the following.
bind M-[2~ insert-mode
On many keyboards, the above key sequence is generated when one presses the insert key, so with this key binding, one can toggle between the emacs-mode insert and overwrite modes by hitting one key. One could also do it by typing out the above sequence of characters one by one. As explained above, the M- part of this sequence can be typed either by pressing the ESCAPE key before the following key, or by pressing the META key at the same time as the following key. Thus if you had set the above key binding, and the insert key on your keyboard didn't generate the above key sequence, you could still type it in either of the following 2 ways.
If you set a key binding for a key sequence that is already bound to a function, the new binding overrides the old one. If in the new binding you omit the name of the new function to bind to the key sequence, the original binding becomes undefined.
Starting with versions of libtecla later than 1.3.3 it is now possible to bind key sequences that begin with a printable character. Previously key sequences were required to start with a CONTROL or META character.
Note that the special keywords "up", "down", "left", and "right" refer to the arrow keys, and are thus not treated as key sequences. So, for example, to rebind the up and down arrow keys to use the history search mechanism instead of the simple history recall method, you could place the following in your configuration file:
bind up history-search-backwards bind down history-search-backwards
To unbind an existing binding, you can do this with the bind command by omitting to name any action to rebind the key sequence to. For example, by not specifying an action function, the following command unbinds the default beginning-of-line action from the ^A key sequence:
bind ^A
If you create a ~/.teclarc configuration file, but it appears to have no effect on the program, check the documentation of the program to see if the author chose a different name for this file.
With the default key bindings, pressing the TAB key (aka. ^I) results in tecla attempting to complete the incomplete file name that precedes the cursor. Tecla searches backwards from the cursor, looking for the start of the file name, stopping when it hits either a space or the start of the line. If more than one file has the specified prefix, then tecla completes the file name up to the point at which the ambiguous matches start to differ, then lists the possible matches.
In addition to literally written file names, tecla can complete files that start with ~/ and ~user/ expressions and that contain $envvar expressions. In particular, if you hit TAB within an incomplete ~user, expression, tecla will attempt to complete the username, listing any ambiguous matches.
The completion binding is implemented using the cpl_complete_word() function, which is also available separately to users of this library. See the cpl_complete_word(3TECLA) man page for more details.
With the default key bindings, pressing ^X* causes tecla to expand the file name that precedes the cursor, replacing ~/ and ~user/ expressions with the corresponding home directories, and replacing $envvar expressions with the value of the specified environment variable, then if there are any wildcards, replacing the so far expanded file name with a space-separated list of the files which match the wild cards.
The expansion binding is implemented using the ef_expand_file() function. See the ef_expand_file(3TECLA) man page for more details.
Every time that a new line is entered by the user, it is appended to a list of historical input lines maintained within the GetLine resource object. You can traverse up and down this list using the up and down arrow keys. Alternatively, you can do the same with the ^P, and ^N keys, and in vi command mode you can alternatively use the k and j characters. Thus pressing up-arrow once, replaces the current input line with the previously entered line. Pressing up-arrow again, replaces this with the line that was entered before it, etc.. Having gone back one or more lines into the history list, one can return to newer lines by pressing down-arrow one or more times. If you do this sufficient times, you will return to the original line that you were entering when you first hit up-arrow.
Note that in vi mode, all of the history recall functions switch the library into command mode.
In emacs mode the M-p and M-n keys work just like the ^P and ^N keys, except that they skip all but those historical lines which share the prefix that precedes the cursor. In vi command mode the upper case 'K' and 'J' characters do the same thing, except that the string that they search for includes the character under the cursor as well as what precedes it.
Thus for example, suppose that you were in emacs mode, and you had just entered the following list of commands in the order shown:
ls ~/tecla/ cd ~/tecla ls -l getline.c emacs ~/tecla/getline.c
If you next typed:
ls
and then hit M-p, then rather than returning the previously typed emacs line, which doesn't start with "ls", tecla would recall the "ls -l getline.c" line. Pressing M-p again would recall the "ls ~/tecla/" line.
Note that if the string that you are searching for, contains any of the special characters, *, ?, or '[', then it is interpretted as a pattern to be matched. Thus, cotinuing with the above example, after typing in the list of commands shown, if you then typed:
*tecla*
and hit M-p, then the "emacs ~/tecla/getline.c" line would be recalled first, since it contains the word tecla somewhere in the line, Similarly, hitting M-p again, would recall the "ls ~/tecla/" line, and hitting it once more would recall the "ls ~/tecla/" line. The pattern syntax is the same as that described for file name expansion, in the ef_expand_file(3TECLA).
Authors of programs that use the tecla library have the option of saving historical command-lines in a file before exiting, and subsequently reading them back in from this file when the program is next started. There is no standard name for this file, since it makes sense for each application to use its own history file, so that commands from different applications don't get mixed up.
Since libtecla version 1.4.0, tecla has been 8-bit clean. This means that all 8-bit characters that are printable in the user's current locale are now displayed verbatim and included in the returned input line. Assuming that the calling program correctly contains a call like the following,
setlocale(LC_CTYPE, "");
then the current locale is determined by the first of the environment variables LC_CTYPE, LC_ALL, and LANG, that is found to contain a valid locale name. If none of these variables are defined, or the program neglects to call setlocale, then the default C locale is used, which is US 7-bit ASCII. On most unix-like platforms, you can get a list of valid locales by typing the command:
locale -a
Beware that in most locales other than the default C locale, META characters become printable, and they are then no longer considered to match M-c style key bindings. This allows international characters to be entered with the compose key without unexpectedly triggering META key bindings. You can still invoke META bindings, since there are actually two ways to do this. For example the binding M-c can also be invoked by pressing the ESCAPE key momentarily, then pressing the c key, and this will work regardless of locale. Moreover, many modern terminal emulators, such as gnome's gnome-terminal's and KDE's konsole terminals, already generate escape pairs like this when you use the META key, rather than a real meta character, and other emulators usually have a way to request this behavior, so you can continue to use the META key on most systems.
For example, although xterm terminal emulators generate real 8-bit meta characters by default when you use the META key, they can be configured to output the equivalent escape pair by setting their EightBitInput X resource to False. You can either do this by placing a line like the following in your ~/.Xdefaults file,
XTerm*EightBitInput: False
or by starting an xterm with an -xrm '*EightBitInput: False' command-line argument. In recent versions of xterm you can toggle this feature on and off with the 'Meta Sends Escape' option in the menu that is displayed when you press the left mouse button and the CONTROL key within an xterm window. In CDE, dtterms can be similarly coerced to generate escape pairs in place of meta characters, by setting the Dtterm*KshMode resource to True.
If you don't have a keyboard that generates all of the international characters that you need, there is usually a compose key that will allow you to enter special characters, or a way to create one. For example, under X windows on unix-like systems, if your keyboard doesn't have a compose key, you can designate a redundant key to serve this purpose with the xmodmap command. For example, on many PC keyboards there is a microsoft-windows key, which is otherwise useless under Linux. On a laptop, for example, the xev program might report that pressing this key generates keycode 115. To turn this key into a COMPOSE key, do the following:
xmodmap -e 'keycode 115 = Multi_key'
Type this key followed by a " character to enter an 'I' with a umlaut over it.
The following is a list of the editing functions provided by the tecla library. The names in the leftmost column of the list can be used in configuration files to specify which function a given key or combination of keys should invoke. They are also used in the next two sections to list the default key bindings in emacs and vi modes.
user-interrupt
suspend
stop-output
start-output
literal-next
cursor-right
cursor-left
insert-mode
beginning-of-line
end-of-line
delete-line
kill-line
backward-kill-line
forward-word
forward-to-word
backward-word
goto-column
find-parenthesis
forward-delete-char
backward-delete-char
list-or-eof
del-char-or-list-or-eof
forward-delete-word
backward-delete-word
upcase-word
downcase-word
capitalize-word
change-case
redisplay
clear-screen
transpose-chars
set-mark
exchange-point-and-mark
kill-region
copy-region-as-kill
yank
append-yank
up-history
down-history
history-search-backward
history-search-forward
history-re-search-backward
history-re-search-forward
complete-word
expand-filename
list-glob
list-history
read-from-file
read-init-files
beginning-of-history
end-of-history
digit-argument
newline
repeat-history
ring-bell
forward-copy-char
backward-copy-char
forward-copy-word
backward-copy-word
forward-find-char
backward-find-char
forward-to-char
backward-to-char
repeat-find-char
invert-refind-char
delete-to-column
delete-to-parenthesis
forward-delete-find
backward-delete-find
forward-delete-to
backward-delete-to
delete-refind
delete-invert-refind
copy-to-column
copy-to-parenthesis
forward-copy-find
backward-copy-find
forward-copy-to
backward-copy-to
copy-refind
copy-invert-refind
vi-mode
emacs-mode
vi-insert
vi-overwrite
vi-insert-at-bol
vi-append-at-eol
vi-append
vi-replace-char
vi-forward-change-char
vi-backward-change-char
vi-forward-change-word
vi-backward-change-word
vi-change-rest-of-line
vi-change-line
vi-change-to-bol
vi-change-to-column
vi-change-to-parenthesis
vi-forward-change-find
vi-backward-change-find
vi-forward-change-to
vi-backward-change-to
vi-change-refind
vi-change-invert-refind
vi-undo
vi-repeat-change
The following default key bindings, which can be overriden by the tecla configuration file, are designed to mimic most of the bindings of the unix tcsh shell shell, when it is in emacs editing mode.
This is the default editing mode of the tecla library.
Under UNIX the terminal driver sets a number of special keys for certain functions. The tecla library attempts to use the same key bindings to maintain consistency. The key sequences shown for the following 6 bindings are thus just examples of what they will probably be set to. If you have used the stty command to change these keys, then the default bindings should match.
^C
^\fR
^Z
^Q
^S
^V
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
left
up
down
The remaining bindings don't depend on the terminal setttings.
^F
^B
M-i
^A
^E
^U
^K
M-f
M-b
^D
^H
^?
M-d
M-^H
M-^?
M-u
M-l
M-c
^R
^L
^T
^@
^X^X
^W
M-w
^Y
^P
^N
M-p
M-n
^I
^X*
^X^F
^X^R
^Xg
^Xh
M-<
M->
fR
M-o
M-^V
M-0, M-1, ... M-9
Note that ^I is what the TAB key generates, and that ^@ can be generated not only by pressing the CONTROL key and the @ key simultaneously, but also by pressing the CONTROL key and the space bar at the same time.
The following default key bindings are designed to mimic the vi style of editing as closely as possible. This means that very few editing functions are provided in the initial character input mode, editing functions instead being provided by the vi command mode. The vi command mode is entered whenever the ESCAPE character is pressed, or whenever a key sequence that starts with a meta character is entered. In addition to mimicing vi, libtecla provides bindings for tab completion, wild-card expansion of file names, and historical line recall.
To learn how to tell the tecla library to use vi mode instead of the default emacs editing mode, see the earlier section entitled The Tecla Configuration File.
Under UNIX the terminal driver sets a number of special keys for certain functions. The tecla library attempts to use the same key bindings to maintain consistency, binding them both in input mode and in command mode. The key sequences shown for the following 6 bindings are thus just examples of what they will probably be set to. If you have used the stty command to change these keys, then the default bindings should match.
^C
^\fR
^Z
^Q
^S
^V
M-^C
M-^\fR
M-^Z
M-^Q
M-^S
Note that above, most of the bindings are defined twice, once as a raw control code like ^C and then a second time as a META character like M-^C. The former is the binding for vi input mode, whereas the latter is the binding for vi command mode. Once in command mode all key sequences that the user types that they don't explicitly start with an ESCAPE or a META key, have their first key secretly converted to a META character before the key sequence is looked up in the key binding table. Thus, once in command mode, when you type the letter i, for example, the tecla library actually looks up the binding for M-i.
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
left
up
down
The cursor keys normally generate a key sequence that start with an ESCAPE character, so beware that using the arrow keys will put you into command mode (if you aren't already in command mode).
The following are the terminal-independent key bindings for vi input mode.
^D
^G
^H
^I
fR
^L
^N
^P
^R
^U
^W
^X*
^X^F
^X^R
^?
The following are the key bindings that are defined in vi command mode, this being specified by them all starting with a META character. As mentioned above, once in command mode the initial meta character is optional. For example, you might enter command mode by typing ESCAPE, and then press 'H' twice to move the cursor two positions to the left. Both 'H' characters get quietly converted to M-h before being compared to the key binding table, the first one because ESCAPE followed by a character is always converted to the equivalent META character, and the second because command mode was already active.
M-\fR
M-$
M-*
M-+
M--
M-<
M->
M-^
M-
M-,
M-|
M-~
M-.
M-%
M-a
M-A
M-b
M-B
M-C
M-cb
M-cB
M-cc
M-ce
M-cE
M-cw
M-cW
M-cF
M-cf
M-cT
M-ct
M-c;
M-c,
M-ch
M-c^H
M-c^?
M-cl
M-c\fR
M-c^
M-c0
M-c$
M-c|
M-c%
M-dh
M-d^H
M-d^?
M-dl
M-d
M-dd
M-db
M-dB
M-de
M-dE
M-dw
M-dW
M-dF
M-df
M-dT
M-dt
M-d;
M-d,
M-d^
M-d0
M-d$
M-D
M-d|
M-d%
M-e
M-E
M-f
M-F
M--
M-h
M-H
M-i
M-I
M-j
M-J
M-k
M-K
M-l
M-L
M-n
M-N
M-p
M-P
M-r
M-R
M-s
M-S
M-t
M-T
M-u
M-w
M-W
M-x
M-X
M-yh
M-y^H
M-y^?
M-yl
M-y\fR
M-ye
M-yE
M-yw
M-yW
M-yb
M-yB
M-yf
M-yF
M-yt
M-yT
M-y;
M-y,
M-y^
M-y0
M-y$
M-yy
M-Y
M-y|
M-y%
M-^E
M-^H
M-^?
M-^L
M-^N
M-^P
M-^R
M-^D
M-^I
M-
M-fR
M-^X^R
M-^Xh
M-0, M-1, ... M-9
Note that ^I is what the TAB key generates.
Many of the key binding functions described previously, take an optional count, typed in before the target key sequence. This is interpreted as a repeat count by most bindings. A notable exception is the goto-column binding, which interprets the count as a column number.
By default you can specify this count argument by pressing the META key while typing in the numeric count. This relies on the digit-argument action being bound to 'META-0', 'META-1' etc. Once any one of these bindings has been activated, you can optionally take your finger off the META key to type in the rest of the number, since every numeric digit thereafter is treated as part of the number, unless it is preceded by the literal-next binding. As soon as a non-digit, or literal digit key is pressed the repeat count is terminated and either causes the just typed character to be added to the line that many times, or causes the next key binding function to be given that argument.
For example, in emacs mode, typing:
M-12a
causes the letter 'a' to be added to the line 12 times, whereas
M-4M-c
Capitalizes the next 4 words.
In vi command mode the meta modifier is automatically added to all characters typed in, so to enter a count in vi command-mode, just involves typing in the number, just as it does in the vi editor itself. So for example, in vi command mode, typing:
4w2x
moves the cursor four words to the right, then deletes two characters.
You can also bind digit-argument to other key sequences. If these end in a numeric digit, that digit gets appended to the current repeat count. If it doesn't end in a numeric digit, a new repeat count is started with a value of zero, and can be completed by typing in the number, after letting go of the key which triggered the digit-argument action.
/usr/lib/libtecla.so
/usr/include/libtecla.h
~/.teclarc
See attributes(5) for descriptions of the following attributes:
|
vi(1), cpl_complete_word(3TECLA), ef_expand_file(3TECLA), gl_get_line(3TECLA), gl_io_mode(3TECLA), libtecla(3LIB), pca_lookup_file(3TECLA), attributes(5)
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |