个人工具

“UbuntuHelp:HowToReadline”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/HowToReadline}} {{Languages|UbuntuHelp:HowToReadline}} If you use a Bash shell, you might know it uses the Readline library for editing command li...)
 
 
(未显示同一用户的7个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/HowToReadline}}
 
{{From|https://help.ubuntu.com/community/HowToReadline}}
 
{{Languages|UbuntuHelp:HowToReadline}}
 
{{Languages|UbuntuHelp:HowToReadline}}
 +
<<Include(Tag/ContentCleanup)>>
 +
<<Include(Tag/StyleCleanup)>>
 
If you use a Bash shell, you might know it uses the Readline
 
If you use a Bash shell, you might know it uses the Readline
 
library for editing command lines. Many other programs use it too.
 
library for editing command lines. Many other programs use it too.
第11行: 第13行:
 
Enter the Bash builtin command <code><nowiki>bind -P</nowiki></code> for a complete list of
 
Enter the Bash builtin command <code><nowiki>bind -P</nowiki></code> for a complete list of
 
the bindings.
 
the bindings.
 
 
This article describes how to add some keys and key combinations to the
 
This article describes how to add some keys and key combinations to the
 
repertoire. A new Readline configuration file is attached which
 
repertoire. A new Readline configuration file is attached which
 
defines the following keys:
 
defines the following keys:
 
 
{|border="1" cellspacing="0"
 
{|border="1" cellspacing="0"
|<><Ctrl><arrow>||Move forwards and backwards a word at a time<sup>1</sup>
+
|||Move forwards and backwards a word at a time<sup>1</sup>
 
|-
 
|-
|<><Ctrl><Delete>||Delete word to right of cursor
+
|||Delete word to right of cursor
 
|-
 
|-
|<><Ctrl><Backspace>||Delete word to left of cursor
+
|||Delete word to left of cursor
 
|-
 
|-
|<><Shift><Delete>||Delete from cursor to end of line
+
|||Delete from cursor to end of line
 
|-
 
|-
|<><Shift><Backspace>||Delete from cursor to start of line
+
|||Delete from cursor to start of line
 
|-
 
|-
|<><Insert>||Toggle overwrite/insert mode<sup>2</sup>
+
|||Toggle overwrite/insert mode<sup>2</sup>
 
|}
 
|}
 
 
<sup>1</sup> This has been part of the default configuration since Kubuntu release 6.06,
 
<sup>1</sup> This has been part of the default configuration since Kubuntu release 6.06,
 
but is included here for completeness.
 
but is included here for completeness.
<br>
+
<<BR>>
 
<sup>2</sup> Each call to Readline starts in insert mode; the Insert key doesn't
 
<sup>2</sup> Each call to Readline starts in insert mode; the Insert key doesn't
 
"stick" between calls.
 
"stick" between calls.
 
 
A ''word'' is defined by Readline to be a sequence of letters or numbers;
 
A ''word'' is defined by Readline to be a sequence of letters or numbers;
 
it is not possible to change this definition. Other parts of Ubuntu might
 
it is not possible to change this definition. Other parts of Ubuntu might
第41行: 第39行:
 
characters in ''':@-./_~''' to be part of a word when double clicking
 
characters in ''':@-./_~''' to be part of a word when double clicking
 
(see '''Settings/Configure Konsole''').
 
(see '''Settings/Configure Konsole''').
 
 
==== Keyboard map ====
 
==== Keyboard map ====
 
 
Before installing the new Readline configuration file, it is necessary to
 
Before installing the new Readline configuration file, it is necessary to
 
configure the terminal emulator to emit a unique byte sequence for each
 
configure the terminal emulator to emit a unique byte sequence for each
第50行: 第46行:
 
for <Ctrl><Backspace> as for <Shift><Backspace>, which is just the same
 
for <Ctrl><Backspace> as for <Shift><Backspace>, which is just the same
 
as for <Backspace> on its own.
 
as for <Backspace> on its own.
 
+
Attached to this article is [[UbuntuHelp:attachment:myKubuntu.keytab|attachment:myKubuntu.keytab]], which configures
Attached to this article is https://help.ubuntu.com/community/HowToReadline?action=AttachFile&do=get&target=myKubuntu.keytab%2C which configures
+
 
Konsole to emit the required byte sequences. The simplest way to install it
 
Konsole to emit the required byte sequences. The simplest way to install it
 
is to put it in `~/.kde/share/apps/konsole` ('''~''' is the
 
is to put it in `~/.kde/share/apps/konsole` ('''~''' is the
 
conventional notation for "my home directory"). Alternatively, you could make
 
conventional notation for "my home directory"). Alternatively, you could make
 
a system-wide change by putting the keytab in `/usr/share/apps/konsole`.
 
a system-wide change by putting the keytab in `/usr/share/apps/konsole`.
 
 
Rather than downloading the entire table, you could download the
 
Rather than downloading the entire table, you could download the
patch in https://help.ubuntu.com/community/HowToReadline?action=AttachFile&do=get&target=default.keytab.patch and apply it to the default
+
patch in [[UbuntuHelp:attachment:default.keytab.patch|attachment:default.keytab.patch]] and apply it to the default
 
keyboard table. The default keyboard table doesn't exist as a .keytab file
 
keyboard table. The default keyboard table doesn't exist as a .keytab file
 
since it's built into Konsole; instead, it's available in
 
since it's built into Konsole; instead, it's available in
第67行: 第61行:
 
patch myKubuntu.keytab default.keytab.patch
 
patch myKubuntu.keytab default.keytab.patch
 
</nowiki></pre>
 
</nowiki></pre>
 
 
After installing myKubuntu.keytab as outlined above, start a new
 
After installing myKubuntu.keytab as outlined above, start a new
 
Konsole session and select
 
Konsole session and select
 
'''Settings/Keyboard/XTerm (myKubuntu)'''.
 
'''Settings/Keyboard/XTerm (myKubuntu)'''.
 
If you're happy with this after testing, select '''Settings/Save as Default'''.
 
If you're happy with this after testing, select '''Settings/Save as Default'''.
 
 
If you don't use the default Konsole keyboard table, and need to modify a
 
If you don't use the default Konsole keyboard table, and need to modify a
 
different keytab file, a useful technique during development is to start
 
different keytab file, a useful technique during development is to start
第82行: 第74行:
 
See `/usr/share/doc/konsole/README.KeyTab` for details of the format of
 
See `/usr/share/doc/konsole/README.KeyTab` for details of the format of
 
the keytab file.
 
the keytab file.
 
 
[FIXME: not described are the GNOME terminal emulator, the Linux tty
 
[FIXME: not described are the GNOME terminal emulator, the Linux tty
 
console, or classic xterm.]
 
console, or classic xterm.]
 
 
==== Readline configuration ====
 
==== Readline configuration ====
 
 
After your terminal emulator is configured to emit the required byte
 
After your terminal emulator is configured to emit the required byte
 
sequences, it's time to configure Readline. Download the file
 
sequences, it's time to configure Readline. Download the file
https://help.ubuntu.com/community/HowToReadline?action=AttachFile&do=get&target=inputrc and install it either in your home directory as
+
[[UbuntuHelp:attachment:inputrc|attachment:inputrc]] and install it either in your home directory as
 
`.inputrc` or as a replacement for the existing file `/etc/inputrc`.
 
`.inputrc` or as a replacement for the existing file `/etc/inputrc`.
 
 
Again, you might prefer to apply a patch instead of installing a complete
 
Again, you might prefer to apply a patch instead of installing a complete
replacement. Download https://help.ubuntu.com/community/inputrc.patch (say, to `?action=AttachFile&do=get&target=tmp%60%29 and with root
+
replacement. Download [[UbuntuHelp:attachment:inputrc.patch|attachment:inputrc.patch]] (say, to `/tmp`) and with root
 
privilege issue the command:
 
privilege issue the command:
 
<pre><nowiki>
 
<pre><nowiki>
 
patch --backup /etc/inputrc /tmp/inputrc.patch
 
patch --backup /etc/inputrc /tmp/inputrc.patch
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Note this creates a backup file, most likely called `/etc/inputrc.orig`
 
Note this creates a backup file, most likely called `/etc/inputrc.orig`
 
(see `patch(1)` for details).
 
(see `patch(1)` for details).
 
 
Remember to start a new session before testing and, if necessary, change the
 
Remember to start a new session before testing and, if necessary, change the
 
keyboard table.
 
keyboard table.
 
+
==== Other terminal emulators ====
 +
The following line in /etc/inputrc makes the GNOME terminal emulator use <Ctrl><Delete> to delete the word in front of the cursor:
 +
<pre><nowiki>
 +
"\e[3;5~": kill-word
 +
</nowiki></pre>
 +
However, I have not yet found a way to use <Ctrl><Backspace>.
 
=== Summary ===
 
=== Summary ===
 
 
You have modified your terminal emulator to emit the byte sequences required
 
You have modified your terminal emulator to emit the byte sequences required
 
by your custom Readline configuration file. Now Bash and other
 
by your custom Readline configuration file. Now Bash and other
 
command-line programs can use the keys defined in the table above, as well
 
command-line programs can use the keys defined in the table above, as well
 
as Home, End, etc.
 
as Home, End, etc.
 
 
=== Related Pages ===
 
=== Related Pages ===
 
 
* [http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html GNU Readline Library]
 
* [http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html GNU Readline Library]
 
* [http://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual]
 
* [http://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual]
 
 
----
 
----
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
+
[[category:CategoryCommandLine]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2009年11月17日 (二) 19:26的最新版本


<<Include(Tag/ContentCleanup)>> <<Include(Tag/StyleCleanup)>> If you use a Bash shell, you might know it uses the Readline library for editing command lines. Many other programs use it too. The Readline configuration supplied with Ubuntu and Kubuntu allows you to use some obvious keys, such as the left/right arrow keys, for moving around and editing the command line, but you might want a few features beyond those provided. In fact, Readline has a rich set of default key bindings, but they can be difficult to remember or awkward to use. For instance, <Alt>d deletes the word to the right of the cursor. Enter the Bash builtin command bind -P for a complete list of the bindings. This article describes how to add some keys and key combinations to the repertoire. A new Readline configuration file is attached which defines the following keys:

Move forwards and backwards a word at a time1
Delete word to right of cursor
Delete word to left of cursor
Delete from cursor to end of line
Delete from cursor to start of line
Toggle overwrite/insert mode2

1 This has been part of the default configuration since Kubuntu release 6.06, but is included here for completeness. <
> 2 Each call to Readline starts in insert mode; the Insert key doesn't "stick" between calls. A word is defined by Readline to be a sequence of letters or numbers; it is not possible to change this definition. Other parts of Ubuntu might define a word differently. For instance, Konsole by default defines the characters in :@-./_~ to be part of a word when double clicking (see Settings/Configure Konsole).

Keyboard map

Before installing the new Readline configuration file, it is necessary to configure the terminal emulator to emit a unique byte sequence for each required key combination. Konsole needs only a small change: with the default XTerm (XFree 4.x.x) keyboard table, it emits the same byte sequence for <Ctrl><Backspace> as for <Shift><Backspace>, which is just the same as for <Backspace> on its own. Attached to this article is attachment:myKubuntu.keytab, which configures Konsole to emit the required byte sequences. The simplest way to install it is to put it in `~/.kde/share/apps/konsole` (~ is the conventional notation for "my home directory"). Alternatively, you could make a system-wide change by putting the keytab in `/usr/share/apps/konsole`. Rather than downloading the entire table, you could download the patch in attachment:default.keytab.patch and apply it to the default keyboard table. The default keyboard table doesn't exist as a .keytab file since it's built into Konsole; instead, it's available in `/usr/share/doc/konsole/README.default.Keytab.gz`. To create the new keytab, issue these commands:

gzip -cd /usr/share/doc/konsole/README.default.Keytab.gz > myKubuntu.keytab
patch myKubuntu.keytab default.keytab.patch

After installing myKubuntu.keytab as outlined above, start a new Konsole session and select Settings/Keyboard/XTerm (myKubuntu). If you're happy with this after testing, select Settings/Save as Default. If you don't use the default Konsole keyboard table, and need to modify a different keytab file, a useful technique during development is to start Konsole with the command konsole --keytab myKubuntu (or whatever name you choose). This allows you to see any error messages from Konsole, for instance those that say a key combination has been defined earlier in the keytab file. To verify a key combination, a useful technique is to start vim, enter Insert mode with i, and enter <Ctrl>v followed by the key combination. See `/usr/share/doc/konsole/README.KeyTab` for details of the format of the keytab file. [FIXME: not described are the GNOME terminal emulator, the Linux tty console, or classic xterm.]

Readline configuration

After your terminal emulator is configured to emit the required byte sequences, it's time to configure Readline. Download the file attachment:inputrc and install it either in your home directory as `.inputrc` or as a replacement for the existing file `/etc/inputrc`. Again, you might prefer to apply a patch instead of installing a complete replacement. Download attachment:inputrc.patch (say, to `/tmp`) and with root privilege issue the command:

patch --backup /etc/inputrc /tmp/inputrc.patch

Note this creates a backup file, most likely called `/etc/inputrc.orig` (see `patch(1)` for details). Remember to start a new session before testing and, if necessary, change the keyboard table.

Other terminal emulators

The following line in /etc/inputrc makes the GNOME terminal emulator use <Ctrl><Delete> to delete the word in front of the cursor:

"\e[3;5~": kill-word

However, I have not yet found a way to use <Ctrl><Backspace>.

Summary

You have modified your terminal emulator to emit the byte sequences required by your custom Readline configuration file. Now Bash and other command-line programs can use the keys defined in the table above, as well as Home, End, etc.

Related Pages