Alacritty: Difference between revisions

From ArchWiki
(Add zh-hans interlanguage link.)
(→‎Colors: updated color scheme link to current repository)
 
(22 intermediate revisions by 10 users not shown)
Line 13: Line 13:
== Configuration ==
== Configuration ==


''Alacritty'' searches for a configuration file at the following places in this order:
Alacritty searches for a configuration file at the following places in this order:


* {{ic|$XDG_CONFIG_HOME/alacritty/alacritty.yml}}
* {{ic|$XDG_CONFIG_HOME/alacritty/alacritty.toml}}
* {{ic|$XDG_CONFIG_HOME/alacritty.yml}}
* {{ic|$XDG_CONFIG_HOME/alacritty.toml}}
* {{ic|$HOME/.config/alacritty/alacritty.yml}}
* {{ic|$HOME/.config/alacritty/alacritty.toml}}
* {{ic|$HOME/.alacritty.yml}}
* {{ic|$HOME/.alacritty.toml}}


Copy the example configuration file at {{ic|/usr/share/doc/alacritty/example/alacritty.yml}} to one of those places and uncomment the settings you want to change. Most settings take effect as soon as you save the file.
Versions before 0.13.0 used a YAML configuration file. Old YAML config files can be converted to TOML by running {{ic|alacritty migrate}}. However, automatic migration drops all comments.
 
Alacritty does not provide a configuration file by default. Configuration options can be found at [https://alacritty.org/config-alacritty.html the project's homepage]. If the {{ic|live_config_reload}} option is enabled (default), most settings will take effect as soon as you save the configuration file.


=== Colors ===
=== Colors ===


See [https://github.com/alacritty/alacritty/wiki/Color-schemes the upstream wiki] for a list of available color schemes. If your preferred color scheme is on the list, paste the provided code into your configuration file.
See [https://github.com/alacritty/alacritty-theme the alacritty-theme repository] for a list of available color schemes. If your preferred color scheme is on the list, paste the provided code into your configuration file.


=== Font ===
=== Font ===
Line 30: Line 32:
If you do not want to use your system’s default font, you can specify a different font by changing the following lines:
If you do not want to use your system’s default font, you can specify a different font by changing the following lines:


{{bc|
{{bc|1=
font:
[font]
  normal:
size = 12.0
    family: monospace
    style: Regular


  bold:
[font.bold]
    family: monospace
family = "monospace"
    style: Bold
style = "Bold"


  italic:
[font.bold_italic]
    family: monospace
family = "monospace"
    style: Italic
style = "Bold Italic"


  bold_italic:
[font.italic]
    family: monospace
family = "monospace"
    style: Bold Italic
style = "Italic"


  size: 11
[font.normal]
family = "monospace"
style = "Regular"
}}
}}


Line 63: Line 65:
Add the following lines to your configuration file to spawn a new instance of ''Alacritty'' in the current working directory by pressing {{ic|Ctrl+Shift+Enter}}:
Add the following lines to your configuration file to spawn a new instance of ''Alacritty'' in the current working directory by pressing {{ic|Ctrl+Shift+Enter}}:


  key_bindings:
  [keyboard]
  - { key: Return,   mods: Control|Shift, action: SpawnNewInstance }
bindings = [
    { key = "Return", mods = "Control|Shift", action = "SpawnNewInstance" }
]


=== "user@host:cwd" in window title bar ===
=== Vi mode and copy/paste ===


The window title bar shows "Alacritty" unlike other terminal emulators under Arch, which by default show "user@host:cwd". See {{Bug|70752}}.
The vi mode allows moving around Alacritty's viewport and scrollback using the keyboard. By default, you can toggle it using {{ic|Ctrl+Shift+Space}}. To copy, you can either use a mouse to select and press {{ic|Ctrl+Shift+c}}, or enter Vi mode, start a selection using {{ic|v}}, move around with {{ic|hjkl}} like in vim, and copy the selection with {{ic|y}}. To paste, press {{ic|Ctrl+Shift+v}}. To copy/paste to/from X clipboard, you can use a mouse selection to copy and a middle mouse click to paste.
 
If you want the Arch default behavior to apply to all your users in Alacritty, you need to edit your {{ic|/etc/bash.bashrc}} file.
 
Find the case statements that set the {{ic|$PROMPT_COMMAND}} for other terminals:


case ${TERM} in
=== Hints ===
  xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
      PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
    ;;
  screen*)
    PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
    ;;
esac


Then edit the line {{ic|xterm*{{!}}rxvt*{{!}}Eterm{{!}}aterm{{!}}kterm{{!}}gnome*)}} to add {{ic|alacritty*}} so that it reads {{ic|xterm*{{!}}rxvt*{{!}}Eterm{{!}}alacritty*{{!}}aterm{{!}}kterm{{!}}gnome*)}}.
Terminal hints can be used to find text or hyperlinks in the visible part of the terminal and pipe it to other applications. By default, Alacritty provides hinting URLs via the {{ic|Ctrl+Shift+U}} shortcut and opens them with [[xdg-open]]. See the {{ic|HINTS}} section of [https://alacritty.org/config-alacritty.html Alacritty TOML configuration manual] for details.


=== Vi mode and copy/paste ===
For example, to make {{ic|''filename''.rs:''line'':''character''}} file hints (e.g. {{ic|my_crate/src/server.rs:181:49}}) clickable and open in [[Visual Studio Code]], one can add the following section to Alacritty's TOML config:


The vi mode allows moving around Alacritty's viewport and scrollback using the keyboard. By default, you can toggle it using {{ic|Ctrl+Shift+Space}}. To copy, you can either use a mouse to select and press {{ic|Ctrl+Shift+c}}, or enter Vi mode, start a selection using {{ic|v}}, move around with {{ic|hjkl}} like in vim, and copy the selection with {{ic|y}}. To paste, press {{ic|Ctrl+Shift+v}}. To copy/paste to/from X clipboard, you can use a mouse selection to copy and a middle mouse click to paste.
{{hc|alacritty.toml|output=<nowiki>
[[hints.enabled]]
regex = "[^ ]+\\.rs:\\d+:\\d+"
command = { program = "code", args = [ "--goto" ] }
mouse = { enabled = true }
</nowiki>}}


=== Regex hints ===
Multiple types of regex-based hints can be added by adding multiple {{ic|<nowiki>[[hints.enabled]]</nowiki>}} sections.
 
Regex hints can be used to find text in the visible part of the terminal and pipe it to other applications. When activated, the matched texts are highlighted with "hints" according to the configured alphabet and presented to the user for selection via keyboard.
 
By default, Alacritty provides hinting URLs via the {{ic|Ctrl+Shift+U}} shortcut and opens them with [[xdg-open]]. See the {{ic|hints:}} section of {{ic|alacritty.yml}} for configuration details.


== Troubleshooting ==
== Troubleshooting ==
Line 133: Line 125:
Alternatively, one can set the value of {{ic|TERM}} in the configuration to {{ic|xterm-256color}} instead of the default {{ic|alacritty}}:
Alternatively, one can set the value of {{ic|TERM}} in the configuration to {{ic|xterm-256color}} instead of the default {{ic|alacritty}}:


{{bc|
{{bc|1=
env:
[env]
  TERM: xterm-256color
TERM = "xterm-256color"
}}
}}
=== Requires hardware supporting GLSL 3.30 ===
You can force Alacritty to use software rendering by launching it with the [[environment variable]] {{ic|1=LIBGL_ALWAYS_SOFTWARE=1}} [https://github.com/alacritty/alacritty/issues/3624#issuecomment-617428381]:
$ LIBGL_ALWAYS_SOFTWARE=1 alacritty


=== No title bar on Wayland GNOME ===
=== No title bar on Wayland GNOME ===
Line 148: Line 134:
When using Wayland GNOME, the title bar is empty and has strange icons. See https://github.com/alacritty/alacritty/issues/4739 for details.
When using Wayland GNOME, the title bar is empty and has strange icons. See https://github.com/alacritty/alacritty/issues/4739 for details.


One workaround is to launch Alacritty with [[XWayland]] instead of native Wayland by setting an empty {{ic|WAYLAND_DISPLAY}} [[environment variable]].
One workaround is to launch Alacritty with [[Xwayland]] instead of native Wayland by setting an empty {{ic|WAYLAND_DISPLAY}} [[environment variable]].


=== Different font size on multiple monitors ===
=== Different font size on multiple monitors ===
Line 159: Line 145:


  $ WINIT_X11_SCALE_FACTOR=1.66 alacritty
  $ WINIT_X11_SCALE_FACTOR=1.66 alacritty
This can also be achieved by setting the value of {{ic|WINIT_X11_SCALE_FACTOR}} in the configuration file:
{{bc|1=
[env]
WINIT_X11_SCALE_FACTOR = "1.66"
}}
=== Color scheme not recovering what was previously set with pywal ===
You can add the following code to your shell's run commands ({{ic|.bashrc}}).
if command -v wal > /dev/null 2>&1 && [ "$TERM" = "alacritty" ]; then
    wal -Rqe
fi
This is better than simply adding {{ic|wal -R}} because
# You only need this to happen in your terminal emulator window.
# {{ic|wal -R}} is pretty slow and you don't need to run that in every subshell.
# You don't need to see StdOut, we use the {{ic|-q}} option.
# We don't need to cause other parts of our desktop to reload colors again as well (i.e. gtk, xrdb, polybar, i3). This is done with the {{ic|-e}} flag.

Latest revision as of 01:26, 25 February 2024

Alacritty is a simple, GPU-accelerated terminal emulator written in Rust. It supports scrollback, 24-bit colors (w:Color depth#True color (24-bit), copy/paste, clicking on URLs, and custom key bindings.

Installation

Install the alacritty package or alacritty-gitAUR for the development version.

Configuration

Alacritty searches for a configuration file at the following places in this order:

  • $XDG_CONFIG_HOME/alacritty/alacritty.toml
  • $XDG_CONFIG_HOME/alacritty.toml
  • $HOME/.config/alacritty/alacritty.toml
  • $HOME/.alacritty.toml

Versions before 0.13.0 used a YAML configuration file. Old YAML config files can be converted to TOML by running alacritty migrate. However, automatic migration drops all comments.

Alacritty does not provide a configuration file by default. Configuration options can be found at the project's homepage. If the live_config_reload option is enabled (default), most settings will take effect as soon as you save the configuration file.

Colors

See the alacritty-theme repository for a list of available color schemes. If your preferred color scheme is on the list, paste the provided code into your configuration file.

Font

If you do not want to use your system’s default font, you can specify a different font by changing the following lines:

[font]
size = 12.0

[font.bold]
family = "monospace"
style = "Bold"

[font.bold_italic]
family = "monospace"
style = "Bold Italic"

[font.italic]
family = "monospace"
style = "Italic"

[font.normal]
family = "monospace"
style = "Regular"

Substitute monospace with a font name from the output of

$ fc-list : family style

Note that some fonts do not provide an Italic style but an Oblique style instead.

Tips and tricks

Spawn new instance in same directory

Add the following lines to your configuration file to spawn a new instance of Alacritty in the current working directory by pressing Ctrl+Shift+Enter:

[keyboard]
bindings = [
   { key = "Return", mods = "Control|Shift", action = "SpawnNewInstance" }
]

Vi mode and copy/paste

The vi mode allows moving around Alacritty's viewport and scrollback using the keyboard. By default, you can toggle it using Ctrl+Shift+Space. To copy, you can either use a mouse to select and press Ctrl+Shift+c, or enter Vi mode, start a selection using v, move around with hjkl like in vim, and copy the selection with y. To paste, press Ctrl+Shift+v. To copy/paste to/from X clipboard, you can use a mouse selection to copy and a middle mouse click to paste.

Hints

Terminal hints can be used to find text or hyperlinks in the visible part of the terminal and pipe it to other applications. By default, Alacritty provides hinting URLs via the Ctrl+Shift+U shortcut and opens them with xdg-open. See the HINTS section of Alacritty TOML configuration manual for details.

For example, to make filename.rs:line:character file hints (e.g. my_crate/src/server.rs:181:49) clickable and open in Visual Studio Code, one can add the following section to Alacritty's TOML config:

alacritty.toml
[[hints.enabled]]
regex = "[^ ]+\\.rs:\\d+:\\d+"
command = { program = "code", args = [ "--goto" ] }
mouse = { enabled = true }

Multiple types of regex-based hints can be added by adding multiple [[hints.enabled]] sections.

Troubleshooting

Mouse not working properly in Vim

Add set ttymouse=sgr and set mouse=a to your .vimrc or switch to Neovim. Also see this issue.

Transparent border in dwm

With dwm, alacritty's borders become transparent. Adding this line to drw.c in the dwm source directory and recompiling fixes the issue:

if (!XftColorAllocName(...))
    die("error, cannot allocate color '%s'", clrname); /* Find this line */
dest->pixel |= 0xff << 24; /* Add this line */

Terminal functionality unavailable in remote shells

When connecting to a remote system from an Alacritty terminal, for instance over SSH, it can occur that the system does not have an entry for Alacritty in its terminfo database (/usr/share/terminfo/a/alacritty*). Therefore, all interactive terminal functionality does not work. This can be fixed by copying the terminfo for Alacritty to the remote server, as described in termite#Terminal issues with SSH.

On the local host, using Alacritty:

$ infocmp > alacritty.terminfo  # export Alacritty's Terminfo
$ scp alacritty.terminfo user@remote-host:~/  # or any other method to copy to the remote host

On the remote host, in the directory where you copied alacritty.terminfo:

$ tic -x alacritty.terminfo  # import Terminfo for current user
$ rm alacritty.terminfo  # optional: remove Terminfo file

Here is a one-liner version of the process above:

$ infocmp | ssh "$user@$host" 'tic -x /dev/stdin'
Note: After this, you will need to start a new SSH session to have the remote shell load the new Terminfo.

Alternatively, one can set the value of TERM in the configuration to xterm-256color instead of the default alacritty:

[env]
TERM = "xterm-256color"

No title bar on Wayland GNOME

When using Wayland GNOME, the title bar is empty and has strange icons. See https://github.com/alacritty/alacritty/issues/4739 for details.

One workaround is to launch Alacritty with Xwayland instead of native Wayland by setting an empty WAYLAND_DISPLAY environment variable.

Different font size on multiple monitors

By default, Alacritty attempts to scale fonts to the appropriate point size on each monitor based on the Device pixel ratio. On some setups with multiple displays, this behavior can result in vastly different physical sizes [1], [2].

To view the existing device pixel ratio values for each monitor, run alacritty -v, move the child window to each monitor, and pay attention to the reported Device pixel ratio in the parent window.

Forcing a constant device pixel ratio using the WINIT_X11_SCALE_FACTOR environment variable may be sufficient to fix the different font size issue:

$ WINIT_X11_SCALE_FACTOR=1.66 alacritty

This can also be achieved by setting the value of WINIT_X11_SCALE_FACTOR in the configuration file:

[env]
WINIT_X11_SCALE_FACTOR = "1.66"

Color scheme not recovering what was previously set with pywal

You can add the following code to your shell's run commands (.bashrc).

if command -v wal > /dev/null 2>&1 && [ "$TERM" = "alacritty" ]; then
    wal -Rqe
fi

This is better than simply adding wal -R because

  1. You only need this to happen in your terminal emulator window.
  2. wal -R is pretty slow and you don't need to run that in every subshell.
  3. You don't need to see StdOut, we use the -q option.
  4. We don't need to cause other parts of our desktop to reload colors again as well (i.e. gtk, xrdb, polybar, i3). This is done with the -e flag.