Allosaurus' Den Almost geek.

Using urxvt(rxvt-unicode) in Arch Linux

| 900 words | tutorials terminal

Using urxvt(rxvt-unicode) in Arch Linux

What is urxvt?

rxvt stands for our extended virtual terminal, and rxvt-unicode(or urxvt) is a customizable terminal emulator which supports international languages through Unicode. One of the features of urxvt is that you can use several Perl extensions to make your life on CLI more easily.

In this article, I will show you how to install and config your own urxvt on archlinux. If you use other Linux distros, aside from reading this article, make sure to refer to your distro manual as well.

Install urxvt

Open your terminal, run:

$ sudo pacman -S rxvt-unicode

You can now give it a try:

$ urxvt

Configuration

Creating .Xresources

.Xresources is a user-level configuration for X client applications, which controls our urxvt. First, we need to create a Xresources file under your home(~) directory:

$ mkdir ~/.Xresources

Or if you have other programs that related to X, a good practice would be to keep their configuration in separate files, and read them in .Xresources. Like:

!~/.Xresources
#include ".Xresources.d/xterm"
#include ".Xresources.d/rxvt-unicode"
...

Caution! If you want to use separate files, make sure you have install a C preprocessor, such as GNU CPP.

To make it simple, here I will go with a plain .Xresources file.

Window and scrollbar

Create the window with the specified X window geometry(default: 80x24).

URxvt.geometry:100x40

If you consider the scrollbar too stupid, just disable it:

URxvt.scrollBar:False

Or put it to the right:

URxvt.scrollBar_right:True

You still not satisfied? This can change the scrollbar style:

!supported style: rxvt, plain, next or xterm.
URxvt.scrollstyle:plain

Font declaration

You can set up your favorite fonts for urxvt. Declare the fonts you want to use like this:

URxvt.font: xft:monaco,\
            xft:Terminus:pixelsize=12,\
            xft:Code2000:pixelsize=12:antialias=false,\
            ...

xft means X FreeType. It’s one of the font description in X. It uses fontconfig libraries. And compared to the other XLF description, it prevents complex font names.

The format for xft font name is:

<family>:<name>=<value>:<name>=<value>...
  • <family>: The font you want to use, like Terminus.
  • <name> : The font property, like pixelsize, spacing, antialias, etc…
  • <value> : The value of the property, like int with pixelsize, bool with antialias.
    For more properties, see this.

Tips: If you are not sure how the font will look like in urxvt, you can run command urxvt -fn "<family>:<name>=<value>..." to test it.

You can declare fonts as many as you want, but the font you declare first will be the main font, which has the highest priority, and the others will be alternative or fall-back fonts(in declaration order).

Caution!: If your font name has hyphens, they must be escaped with backslash(\)twice.

Font spacing

If you feel like your default distance between characters is too wide. You can reduce it by setting the letterSpace variable in .Xresources.

!By default, it's set to 0.
URxvt.letterSpace: -1

Caution!: Be careful of font spacing. If the distance is too short, some of the Unicode characters might not correctly displayed. If you don’t want this to happen, it’s recommended to set font spacing while declaring fonts.

Colors

By default, urxvt is compiled with color supports. It can display up to 256 colors. However, you can specify the color of your own, here is an example:

!Color Theme
URxvt.background: rgb:10/10/10
URxvt.foreground: rgb:d3/d3/d3
URxvt.colorIT: #87af5f
URxvt.colorBD: #d7d7d7
URxvt.colorUL: #87afd7
!!black
URxvt.color0: rgb:10/10/10
URxvt.color8: rgb:4d/4d/4d
!!red
URxvt.color1: rgb:cd/5c/5c
URxvt.color9: rgb:ff/6a/6a
!!green
URxvt.color2: rgb:2e/8b/57
URxvt.color10: rgb:8f/bc/8f
!!yellow
URxvt.color3: rgb:f0/e6/8c
URxvt.color11: rgb:ff/fa/cd
!!blue
URxvt.color4: rgb:b0/c4/de
URxvt.color12: rgb:1e/90/ff
!!magenta
URxvt.color5: rgb:ba/55/d3
URxvt.color13: rgb:db/70/93
!!cyan
URxvt.color6: rgb:46/82/b4
URxvt.color14: rgb:5f/9e/a0
!!white
URxvt.color7: rgb:d3/d3/d3
URxvt.color15: rgb:ff/ff/ff

urxvt supports at least 16 basic colors. The colors 0-7 are the normal colors, while colors 8-15 are their bright counterparts used for highlighting.
colorIT, colorBD, and colorUL mean the colors for italic, bold, and underline respectively.
A web page may give you some ideas about your own color theme!

Useful Perl extensions

You can enable some Perl extensions by including the following line:
First, install the urxvt-perls package from the AUR.

$ yay -S urxvt-perls

And put the extension you would like to use in your .Xresources

URxvt.perl-ext-common: extension_name_1,extension_name_2,...

Open URLs without mouse

URxvt.perl-ext: default,url-select
URxvt.keysym.M-u: perl:url-select:select_next
URxvt.url-select.launcher:path/to/your/browser
URxvt.url-select.underline: true

For now, you can combine key Alt+u to enter selection mode in a file. The last URL in your screen will be selected. You can repeat Alt+u to select the next upward URL. If you hit Return, the selected URL will be opened in your browser. You can also copy the URL by key y.

Simple tabs

URxvt.perl-ext-common: ...,tabbedx,...
URxvt.tabbed.tabbar-fg: 2
URxvt.tabbed.tabbar-bg: 0
URxvt.tabbed.tab-fg: 2
URxvt.tabbed.tab-bg: 0
URxvt.tabbed.autohide:  yes
URxvt.tabbed.new-button:  no
URxvt.tabbed.title: yes

To use this extension, We need to install urxvt-tabbedex package from AUR.If you enable it, you will be able to open multiple tabs in your urxvt(just like what you do in your browser). Press Shift+Down to open a new tab. Press Shift+Up to name a tab, then press Return to confirm.
To control those tabs, use Shift+Left(Right) for going to left(right) tab, and press Ctrl+d to close current tab.

Change font size on the fly

Install urxvt-resize-font from AUR, add it to your Perl extensions.

URxvt.perl-ext-common:...,resize-font,...

Then press Ctrl++ to increase font size and Ctrl+- to decrease font size.

Select paragraph in a file

URxvt.perl-ext-common:...,keyboard-select,...
URxvt.keysym.M-Escape: perl:keyboard-select:activate
URxvt.keysym.M-s: perl:keyboard-select:search

With this extension, you can select, copy, paragraph with vim-like hot-keys.

  • Alt+Esc: Enter selection mode.
  • h/j/k/l : Move cursor left/down/up/right.
  • v/V/Ctrl-v: Toggle normal/line-wise/block-wise selection.
  • y: Copy selection to primary buffer.

References

rxvt-unicode - Arch Wiki
urxvt(1)
urxvt(7)

Unless otherwise noted, the content of this site is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).