暗无天日

=============>DarkSun的个人博客

xterm使用简介

配置xterm其实挺折腾的,没什么特殊要求的话,用urxvt代替吧.

1 配置

1.1 让Alt键发送Escape character

默认xterm中的Alt键是发送八位输入符(eight bit input characters)的, 而类似gnome-terminal,konsole等常见终端Alt键发送的是Escape character.

要让xterm中的Alt表现的跟其他终端一样,需要在 .Xdefaults 中添加如下配置:

XTerm*metaSendsEscape:  true
XTerm*eightBitInput:    false

1.2 正确显示中文

fonts can be specified from the command line, with the options -fn for bitmap font names and -fa for Xft names

使用 -fn 选项可以设置xterm中以何种字体显示内容.

或者在 .Xdefaults 文件中加入

XTerm*Font:       7x13

最好为xterm配置一个等宽的字体,这种字体的每个字符都占用同样的大小. 当一个字体的名称的第十一个字段是c或m时,这个字体就是等宽字体.

根据archwiki中所说,在xterm中使用点阵字体显示中文时会有很多的问题,最好是使用TrueType字体代替.

你可以分别为xterm配置英文字体和中文字体:

下面的配置,让xterm使用DejaVu Sans Mono显示英文,用WenQuanYiDejaVu Sans Mono显示中文.

xterm*faceName: DejaVu Sans Mono:style=Book:antialias=false:size=10
xterm*faceNameDoublesize: WenQuanYi Micro Hei Mono:size=10
xterm*faceSize: 8

最后,我们指定xterm将标题与内容看成UTF-8编码

XTerm*locale: zh_CN.UTF-8
xterm*utf8: true
xterm*utf8Title: true

1.3 滚动栏

使用 -sb 选项可以让xterm显示出滚动条.

或者在 .Xdefaults 文件中加入

XTerm*scrollBar:  true

不过默认xterm的滚动条放在了左边,这有一点怪,我们可以使用 right-bar 选项让它把滚动条放在右边, 或者在 .Xdefaults 文件中加入

XTerm*rightScrollBar:  true

你会在滚动条上看到一块小小的深色区域,它的大小代表你目前可以看到多少输出的部分,而它的位置指示了你现在所在的位置.

然而当你尝试用鼠标左键点击这块深色区域向上拉动时,会发现xterm中的内容毫无变化……

xterm中的滚动方式跟其他程序中用滚动条拉动滚动的方式是不同的:

若你想要向上滚动,则需要在滚动条上按下 鼠标右键 来完成,而且滚动的幅度随着鼠标在滚动条的位置不同而不同.

  1. 若在滚动条的底部区域按下,则一次滚动一页
  2. 若在滚动条的顶部区域按下,则一次滚动一行
  3. 若在滚动条中间区域按下,则一次滚动半页

而若你想要向下滚动的话,则需要改成在滚动条上按下 鼠标左键.

这样一页一页的滚动,着实很麻烦,幸运的是,xterm也能让你像其他程序一样直接跳到滚动条的指定位置处,方法是在滚动条的指定位置处按下 鼠标中键.

你还可以尝试一直按着鼠标中键,然后上下拖动,会发现xterm中的内容也跟着一起滚动,这个操作就跟其他程序中的滚动条操作很类似的.

如果不喜欢用鼠标来滚动,那么你还可以用 Shift+PageUpShift+PageDown 来滚动窗口.

最后要说明的额是,你可以使用 -sl number 选项来指定xterm缓冲多少行的内容,或者在 .Xdefaults 中加入以下内容

XTerm*saveLines:  4096

1.4 log文件

若xterm在编译时开启了logging功能,则可以使用 -l 选项让xterm记录下在xterm中的所有操作.

默认日志文件会存放在调用xterm的目录下,且名称格式为 XtermLog.XXXXXX 或者 Xterm.log.hostname.yyyy.mm.dd.hh.mm.ss.XXXXXX

不过你也可以通过选项 -lf 来指定日志文件的名称. 或者通过配置 LogFile 资源也可以指定日志文件名称.

xterm*LogFile:  "/tmp/xterm.log"

1.5 其他配置

1.5.1 Enable bell urgency

xterm*bellIsUrgent: true

1.5.2 Use color in place of bold and italics

当字体太小时,粗体和斜体字就变得很难阅读了. 可以用不同的颜色来代替粗体与斜体的展示

! Forbid bold font faces; bold type is light blue.
XTerm*colorBDMode: true
XTerm*colorBD: rgb:82/a4/d3
! Do not underscore text, underlined text is white.
XTerm*colorULMode: true
XTerm*colorUL: rgb:e4/e4/e4

1.5.3 Adjust line spacing

XTerm*scaleHeight: 1.01

1.5.4 Remove black border

xterm*borderWidth: 0

1.6 保存当前XTerm的配置

2 复制与粘贴

只要按下鼠标并拖拽鼠标选中要复制的内容就完成复制操作了.

如果要调整选中的区域,可以按住Shift键,然后拖拽鼠标左键进行调整.

如果你想要复制整个单词,那么只需要双击一下鼠标就会发现xterm帮你选中了整个单词.

类似的,如果你想要复制的是整个行,那么只需要三击一下鼠标就会发现xterm帮你选中了整行的内容.

在xterm按下鼠标中键就能完成粘贴操作了.

3 xterm菜单

按住Ctrl,再分别单击鼠标左键,中建和右键,会分别弹出 Main Options, VT Options, VT Fonts 菜单.

此外,若xterm切换到了 Tek 模式下,则Ctrl+鼠标中键弹出的会是 Tek Options 菜单.

3.1 Main Options菜单

Secure Keyboard
attempts to ensure only the xterm window, and no other application, receives your keystrokes. The display changes to reverse video when it is invoked. If the display is not in reverse video, the Secure Keyboard mode is not in effect. Please read the "SECURITY" section of the xterm man page for this option's limitations.
Allow SendEvents
allows other processes to send keypress and mouse events to the xterm window. Because of the security risk, do not enable this unless you are very sure you know what you are doing.
Log to File
The log file will be named Xterm.log.hostname.yyyy.mm.dd.hh.mm.ss.XXXXXX. This file will contain all the printed output and all cursor movements. Logging may be a security risk.
The six Send * Signal menu items
are not often useful, except when your keyboard fails. HUP, TERM and KILL will close the xterm window. KILL should be avoided, as it does not allow any cleanup code to run.
The Quit menu item
will also close the xterm window – it is the same as sending a HUP signal. Most users will use the keyboard combination Ctrl+d or will type exit to close an xterm instance.

3.2 VT Options菜单

Select to Clipboard
Normally, selected text is stored in PRIMARY, to be pasted with Shift+Insert or by using the middle mouse button. By toggling this option to on, selected text will use CLIPBOARD, allowing you to paste the text selected in an xterm window into a GUI application using Ctrl+v. The corresponding XTerm resource is selectToClipboard.
Show Alternate Screen
When you use an a terminal application such as vim, or less, the alternate screen is opened. The main VT window, now hidden, remains in memory. You can view this main window, but not issue any commands in it, by toggling this menu option. You are able to select and copy text from this main window.
Show Tek Window and Switch to Tek Mode
The Tektronix 4014 was a graphics terminal from the 1970s used for CAD and plotting applications. The command line program graph, from plotutils, and the application gnuplot can be made to use xterm's Tek emulation; most people will prefer more modern display options for charting data. See the #Tek 4014 demonstration, below.

3.3 VT Fonts菜单

  • When using XLFD fonts, the first seven menu items will change the font face and the font size used in the current xterm window. If you are using an Xft font, only the font size will change, the font face will not change with the different selections,
  • when using XLFD font names, allows you to switch to the font name stored in the PRIMARY selection (or CLIPBOARD).

3.4 Tek options菜单

The first section's options allow you to change the Tek window font size.

The second set of options are used to move the focus between the Tek emulation window and the main, or VT, window and to close or hide the Tek window.

4 xterm其他参数说明

4.1 -ls选项

ls是login shell的意思,若带此选项运行xterm,则xterm会加载你的~/.bash_profile(bash shell),或者你的~/.login文件(c shell)

4.2 -xrm选项

大多数一般的资源均能被命令行选项明确地设定,例如你可以用 -bg colour 设定窗口背景颜色.但无论如何,有一些资源并没有符合的选项. 为了克服这点,xterm提供一个“捕捉遗漏”的选项 -xrm (X 资源管理器的缩写). -xrm 以一个参数当做资源规范,就如同你在XResource文件中输入的一样.

要注意:在同一命令行你可以使用数次 -xrm,但每一次只能包含一个资源规范, 例如:

xterm -xrm "*background:yellow" -xrm "*foreground:red"

会产生一个黄底红字的xterm窗口.