Using the Terminal
What you can do in the terminal itself: select, copy and paste text, look back through the scrollback and search it, open links, work with the output of each command, change the font size, and what the terminal shows: colors, styles, wide characters, emoji, right-to-left text, pictures and the things a program can show you.
1. Selecting and copying
| To select | Do this |
|---|---|
| Characters | Drag with the left mouse button. |
| Words | Double-click, and drag to take more words. A word is a run of characters without a space. |
| Lines | Triple-click, and drag to take more lines. |
| A rectangle | Hold Ctrl and drag: the selection is the block of cells between the two corners. (Alt and a drag is left to the window manager, which moves the window with it.) |
| Everything | Select All in the terminal's menu: the scrollback and the screen. |
| With the keyboard | Ctrl+Shift+Space (section 5). |
| A command's output | Click the mark of its prompt in the margin (section 7). |
- When you let go of the button, the selected text becomes the PRIMARY selection of X11, which the middle button pastes, here or in another program.
Ctrl+Shift+C, or Copy in the menu, copies the selection to the clipboard. Copy as HTML copies it with its colors and styles (bold, italic, faint, underline, strike) as HTML.- A drag above or below the window scrolls the view, a line every 0.05 seconds while the pointer stays there, and the selection grows with it.
- When a program uses the mouse itself, hold
Shiftto select text. - The selection goes when the terminal changes its number of rows or columns, when a full-screen program starts or ends, and when you clear the scrollback.
2. Pasting
Ctrl+Shift+V, or Paste in the menu, pastes the clipboard.- The middle mouse button and
Shift+Insertpaste the PRIMARY selection: the text last selected in any program. - Pasted text is made safe before the program gets it: line ends become carriage returns (as the Return key sends), and every other control character but the tab is removed, so a paste cannot send a key sequence or end the program's paste mode. A program that asked for bracketed paste (as bash, zsh and vim do) gets the text marked as a paste, so it does not run pasted lines as commands.
- The paste question. When you paste several lines into a program that has not asked for bracketed paste, each line could run as a command. With "Confirm a paste of several lines" on (Preferences > Programs; on at first), the paste waits, and the last line of the terminal asks Paste 3 lines? They can run as commands. Press Enter to paste, or Escape to drop it; other keys do nothing until you answer. A line ends in a line feed, in a carriage return and a line feed, or in a carriage return alone, and the question counts lines of all three kinds; for a single line it says Paste 1 line? It can run as a command. Text with only one line end at its very end does not ask.
- Large texts copied in another program arrive whole when you paste them.
3. The scrollback
Lines that leave the top of the screen go to the scrollback, up to the number of Preferences > View > Scrollback (10000 at first).
| To | Do this |
|---|---|
| Scroll | Turn the mouse wheel (three lines a step), press Shift+Page Up or Shift+Page Down (a screen less one line), or use the scrollbar. |
| Go back to the bottom | Type anything: a key or a paste brings the view back to the cursor. |
| Go from prompt to prompt | Ctrl+Shift+Up and Ctrl+Shift+Down, with shell integration (section 7). |
| Empty it | Clear Scrollback in the terminal's menu. A program can empty it too (clear does, with CSI 3 J). |
- While you look at older lines, new output does not move the view: you keep reading where you are.
- When the window gets wider or narrower, the lines of the screen and of the scrollback are wrapped again at the new width, and the cursor stays with its text.
- A full-screen program (an editor,
less,htop) runs on the terminal's second screen, which has no scrollback. The wheel there sends the Up and Down keys when the program asked for that (mode 1007), and does nothing otherwise.
4. Searching
Ctrl+Shift+F, or Find... in the menu, opens the search bar on the last line of the terminal. Type the text you look for: each match in the view is marked (the theme's search-match colors), and the view goes to the newest match, which gets the search-current colors.
| Key | What it does |
|---|---|
| Enter | Goes to the next older match. |
| Shift+Enter | Goes to the next newer match. At either end, the search goes round to the other end. |
| Backspace | Removes the last character of the text. |
| Alt+C | Upper and lower case are different, or the same again. The bar shows [Aa] while they are different. |
| Alt+R | The text is a pattern (a POSIX extended regular expression), or plain text again. The bar shows [.*]. |
| Escape, or Ctrl+Shift+F | Closes the search. |
The bar says what keys there are, or "not found". A plain search treats upper and lower case as the same for the letters A to Z only. Lines that were wrapped are searched as one line, so a match can go over a line's end. Keys with Ctrl still go to the program while the bar is open, so Ctrl+C stops a program as usual.
5. Selecting with the keyboard
Ctrl+Shift+Space starts the keyboard selection at the cursor. An outline in the cursor's color shows the place the keys move, and the bar on the last line lists the keys. Every key belongs to this mode until it ends.
| Key | What it does |
|---|---|
| Arrows, or h j k l | Move left, down, up, right. |
| w, b | To the start of the next word, or of this word (the word before). |
| 0 or Home, $ or End | To the start of the line, or to its last character. |
| g, G | To the first line of the scrollback, or to the last line. |
| Page Up, Page Down | A screen up or down. |
| v, V | Starts a selection here, by characters (v) or by whole lines (V); the same key again drops it. |
| y or Enter | Copies the selection to the clipboard and to PRIMARY, and ends. |
| Escape or q | Ends without copying. |
6. Links
The terminal finds three kinds of links:
- Hyperlinks a program made (OSC 8), such as the file names of
ls --hyperlink. They have a dotted underline in the theme'slinkcolor. - Addresses in the text: anything of the form
scheme://..., such ashttps://...orfile:///..., and mail addresses written asmailto:name@example.org. The address ends at a space, a quote,<,>,`or|. A full stop, comma, colon, semicolon, exclamation or question mark at its end is not part of it, and neither is a closing bracket that has no opening bracket in the address. - File names, alone or with a line and a column, as compilers print them:
src/main.c,main.c:120,main.c:120:8. A word counts as a file name when it has a letter and a/, an extension or a line number.
Hold Ctrl and move the pointer over the text: a link under the pointer is underlined in the link color. Ctrl+click opens it, when you let go of the button without a drag. Open Link and Copy Link in the menu work on the link under the pointer. Hanshi opens a link with xdg-open; a file name is opened only when the file exists, and a name without a folder is found in the shell's folder. The line and the column of a file name are not passed on: xdg-open gets the file alone (The Window and Tabs).
Ctrl+Shift+O puts a letter on each link in view (a to z, then A to Z: up to 52 links). Type a link's letter to open it; any other key, Escape for example, takes the letters away. When there is no link in view, the bar on the last line says so.
7. Prompts and the output of commands
With shell integration (Shell Integration), the terminal knows where each prompt is, where its command's output is, and how the command ended:
- A mark in the margin at the left of each prompt: green after a command that ended with the status 0, red after one that failed, grey while it runs or when the shell gave no result. The theme's keys are
prompt-success,prompt-failureandprompt-mark. - Click a mark to select the output of that command.
- Double-click a mark to hide the output of that command; the mark becomes hollow and the prompt's line says how many lines it hides, for example "... 120 lines". Double-click again to show it. Only the output of a command that has ended can be hidden. Copy Command Output and Hide or Show Command Output in the menu do the same for the command under the pointer.
- A third quick click on a mark does nothing: a triple-click is taken as the end of a double-click, so it does not select the output again.
Ctrl+Shift+UpandCtrl+Shift+Downbring the prompt above or below the first line in view to the top of the view; down from the last prompt goes back to the bottom. They do nothing while a full-screen program runs.- A theme can give each prompt's line a background of its own (
prompt-line; Sumi and Washi do), and the output of a failed command another one (output-failure) (Themes).
8. The font size
Ctrl+Plus (or Ctrl+=, or the keypad's plus) makes the font one pixel larger, Ctrl+Minus (or the keypad's minus) one pixel smaller, and Ctrl+0 gives back the size of the settings. The size stays between 6 and 72 pixels. The window keeps its size, so the number of rows and columns changes. The keys change only the terminal of the tab that shows, and only until the settings or the theme change again. When a program has asked for the modifyOtherKeys keyboard mode, these keys go to the program instead, and the menu's Larger Text, Smaller Text and Normal Text Size still work. Ctrl+Shift+Minus is not a font key: it types Control+_, a control code that some programs use.
9. Text, colors and styles
- Colors. Programs can use the 16 colors of the theme's palette, the 256 colors of xterm, and any color (24-bit color;
COLORTERM=truecolortells programs so). A program can also change the palette, the default text and background colors and the cursor's color while it runs; Reset Terminal puts them back. - Styles. Bold, faint, italic, underline (single, double, curly, dotted and dashed, each in a color of its own when the program gives one), strike-through, overline, blinking text (it is hidden half of each 1.2 seconds), inverse, and invisible text. The theme decides how each looks: in the built-in themes, bold text is drawn in the bold face and italic text in the italic face; faint text is drawn halfway between its color and the background (Themes).
- Reverse video. A program can swap the default text and background colors of the whole terminal (the visual bell of some programs does this).
- Minimum contrast. With Preferences > View > Minimum contrast above 1, text that is too close to its background is made lighter or darker until it can be read.
- Fonts. Each character that the terminal's font does not have is drawn from another installed font that has it. Draw the terminal in a monospaced font: each cell is as wide as the letter M of the font.
- Wide characters (Chinese, Japanese, Korean, most emoji) take two cells. Combining marks are drawn on the character before them.
- Emoji are drawn in color when a color emoji font is installed. An emoji made of several characters is one character on the screen: emoji joined with U+200D (a family, for example), an emoji with a skin tone, and a flag made of two regional letters. U+FE0F after a narrow emoji makes it two cells wide. It takes one cell or two, and a selection takes it whole. A program can switch this off (mode 2027, Terminal Features).
- Ligatures and joined letters. Each run of text with one font and one color is shaped as a whole: Arabic letters get their joined forms, and a programming font's ligatures (
->as an arrow) are drawn when Ligatures is on. Each letter stays in its own cell, so the joined letters of a font that is not monospaced can have small gaps. - Right-to-left text. A line with Hebrew or Arabic is shown in its reading order, by the Unicode Bidirectional Algorithm, and characters such as brackets are mirrored in right-to-left text. The selection, the search and a copy work on the text in the order the program wrote it. A program can switch this off, and can ask for a line that starts with right-to-left text to start at the right edge (Terminal Features).
- Lines of double width and double height (a DEC feature some programs use for headings) are drawn with the font made twice as wide, or twice as wide and high.
- Theme rules can color words in a program's output, such as "error" in red (Themes).
10. Pictures
Programs can show pictures in the terminal in three ways: as sixel graphics (the DEC format that img2sixel, gnuplot and others write), with iTerm2's inline images (imgcat), and with kitty's graphics protocol (kitty +kitten icat, timg, chafa). A picture covers cells of the terminal, so it scrolls, goes to the scrollback and is erased just as text is. When you change the font size, pictures are scaled to the new size of the cells.
Picture files (PNG, JPEG, GIF and BMP), sixel data and compressed data are taken apart in a separate process locked in a jail (Safety). On a system where the jail cannot be made, those pictures are not shown. Pictures that a program sends as plain pixels (kitty's RGB and RGBA formats, not compressed) need nothing taken apart: Hanshi copies them itself, outside the jail, and shows them either way. A picture is at most 4096 pixels wide and high as it is shown, and a program may send up to 64 MiB of data for one picture.
11. What a program can show you
| What | How it shows |
|---|---|
| Progress (OSC 9;4) | A thin bar at the top of the terminal: in the success color while a job runs, red after an error, grey while it is paused, and full width when the end is not known. |
| A pointer shape (OSC 22) | The mouse pointer over the terminal changes. The names Hanshi knows are text, xterm, pointer, hand, crosshair, wait, progress, move, help, not-allowed, ew-resize, ns-resize, left_ptr and default; another name gives the usual pointer. |
| A status line | A row under the screen, with the cursor's position or with text the program writes. When its tab shows, the window grows by a row for it; otherwise the screen gives up a row (The Window and Tabs). |
| Keyboard lights | A program can switch the Num Lock, Caps Lock and Scroll Lock lights; the X server decides whether a light that follows its key's state takes the change. The lights go off when the terminal closes. |
| The bell, a notification, a title | See The Window and Tabs. |
| Printed text | A program can print the screen, a line, or its own output. The text goes to the print command of Preferences > Programs when the job ends; without one, the terminal says it has no printer. |
With a log file named in Preferences > Programs, everything programs show is also added to that file as text, from the moment the terminal starts.
12. Known limitations
- Indic conjuncts (consonants joined by a virama) are not yet joined into one character.
- Right-to-left text follows the basic rules of the Unicode Bidirectional Algorithm: the explicit direction marks and bracket pairs are not used, and each line is a paragraph of its own.
- Of the addresses without
://, onlymailto:is found as a link in the text. - Of kitty's graphics protocol, a program cannot name a file or shared memory to read, choose a part of a picture, place it at an offset or in layers, or use placeholders (Terminal Features).