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 中的滚动方式跟其他程序中用滚动条拉动滚动的方式是不同的:
若你想要向上滚动,则需要在滚动条上按下 鼠标右键 来完成,而且滚动的幅度随着鼠标在滚动条的位置不同而不同.
- 若在滚动条的底部区域按下,则一次滚动一页
- 若在滚动条的顶部区域按下,则一次滚动一行
- 若在滚动条中间区域按下,则一次滚动半页
而若你想要向下滚动的话,则需要改成在滚动条上按下 鼠标左键。
这样一页一页的滚动,着实很麻烦,幸运的是,xterm也能让你像其他程序一样直接跳到滚动条的指定位置处,方法是在滚动条的指定位置处按下 鼠标中键。
你还可以尝试一直按着鼠标中键,然后上下拖动,会发现 xterm 中的内容也跟着一起滚动,这个操作就跟其他程序中的滚动条操作很类似的。
如果不喜欢用鼠标来滚动,那么你还可以用 Shift+PageUp
和 Shift+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 窗口。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论