# Keys

Every key, command, and setting of the viewer, as F1 lists them inside aless.

To see this list inside aless, press `F1` or type `:help`. Where jless has a key for an action, aless uses the same key. The same list is also in the plain-text file [`keys.txt`](https://aless.tabnas.dev/reference/keys.txt), as the terminal shows it.

## Moving

A count before a key repeats it: `3j` moves down three rows.

| Keys | Does |
|---|---|
| `j` `k`, `↓` `↑`, `Ctrl+N` `Ctrl+P` | Move down and up a row. |
| `Enter` `Backspace` | Move down and up a row, as `j` and `k` do. |
| `h`, `←` | Fold the focused container, or go to its parent. |
| `l`, `→` | Unfold the focused container, or go to its first child. |
| `H` | Go to the parent, and leave it unfolded. |
| `J` `K` | Go to the next and the previous sibling, and stop at the last and the first. |
| `w` `b` | Go forward and back to the next row at another depth. |
| `0`, `^` | Go to the first sibling. |
| `$` | Go to the last sibling. |
| `g`, `Home` | Go to the first row. `Ng` goes to row N. |
| `G`, `End` | Go to the last row. `NG` goes to row N. |
| `Ctrl+F` `Ctrl+B`, `PgDn` `PgUp` | Move a page down and up. |
| `Ctrl+D` `Ctrl+U` | Move half a page down and up. A count sets the distance, and later presses keep it. |
| `Ctrl+E` `Ctrl+Y` | Scroll a row down and up. The focus moves only to keep `scrolloff` rows between it and the edge. |
| `zz` `zt` `zb` | Put the focused row at the centre, the top, or the bottom of the screen. |
| `.` `,` | Scroll a value longer than the screen a character right and left. |
| `;` | Scroll a long value to its end, and back to its start. |
| `Esc` | Drop a count, or the first key of a two-key command. |

## Folding and views

| Keys | Does |
|---|---|
| `Space` | Fold or unfold the focused container. |
| `c` | Fold the focused node and its siblings. |
| `C` | Fold the focused node and its siblings, and everything inside them. |
| `e` | Unfold the focused node and its siblings. |
| `E` | Unfold the focused node and its siblings, and everything inside them. |
| `m` | Switch between data mode and line mode. |
| `%` | Go between a container's opening and closing brackets, in line mode. |
| `s` | Show the source view in place of the tree: the text aless read, at the focused node's line. Any key but the scrolling ones, `:`, and `r` goes back. |
| `<` `>` | Indent each level one space less or more. |

## Versions of a watched file

Each reload that parses is a version. Marks show what the version on screen changed from the one before: yellow for a changed value, green for a new one, a red count for removed ones, and rails from the root down to each change.

| Keys | Does |
|---|---|
| `[` `]` | Show the version before, and the version after, the one on screen. `3[` goes back three. |
| `{` `}` | Show the oldest version kept, and the newest. |
| `d` `D` | Go to the next and the previous change, round the end of the document. |
| `v` | List the versions in the history tab, the newest first. |

## Search

A pattern is a regular expression. It ignores case unless it holds a capital letter or ends in `/s`. The characters `[ ] { }` match themselves.

| Keys | Does |
|---|---|
| `/` `?` | Search forward and backward. `Enter` with no pattern searches for the last pattern again. |
| `n` `N` | Go to the next and the previous match, round the end of the document. |
| `*` `#` | Search forward and backward for the focused node's key. |

## Copy and print

`y` and a second key copy the text to the clipboard. `p` and the same second key print it on screen instead. `pP` prints the path, because `pp` prints the value.

| Keys | Does |
|---|---|
| `yy` `pp` | The value, pretty-printed as JSON |
| `yv` `pv` | The value as JSON on one line |
| `ys` `ps` | A string's contents, without its quotes |
| `yk` `pk` | The key |
| `yp` `pP` | The path, as jless writes it: `.a[0].b` |
| `yb` `pb` | The path, with every step in brackets: `["a"][0]["b"]` |
| `yq` `pq` | The path, as jq writes it |

## Tabs and files

| Keys | Does |
|---|---|
| `Tab` `Shift+Tab` | Go to the next and the previous tab. |
| `q` | Close the tab. Closing the last tab quits. |
| `Ctrl+C` | Quit. |
| `r` | Read the file again now. |
| `W` | Stop or start watching the file. |
| `!` | Show the parse error report full size. `h` and `l` pan a long line. |
| `:` | Start a command, from the Commands list. |
| `F1` | Show this help. |
| `Ctrl+Z` | Suspend aless, on Unix. |

## The explorer

A directory is a tree with the same keys. `m`, `%`, and `s` do nothing in it.

| Keys | Does |
|---|---|
| `Enter` | Open the focused file in a new tab, or fold or unfold a directory. |
| `-` | Go up: the parent directory becomes the root. |
| `yp` | Copy the focused entry's path on disk. |
| `/` | Search the entries listed so far: each row's name, size, and format. |

## The history tab

`v` lists the versions of a watched file in a tab, the newest first, each with what it changed. The tab follows the file as it changes, and closes with the file's tab. `:w` and `:ws` write the focused version. `m`, `%`, and `s` do nothing in it.

| Keys | Does |
|---|---|
| `Enter` | Open the focused version in a tab of its own, which is not watched, at the focused change. |
| `v` | Go to the history tab from a version's own tab, or from the file's tab. |

## Commands

Type `:` and the command, then `Enter`.

| Keys | Does |
|---|---|
| `:open PATH [FORMAT]`, `:e` | Open a file or a directory in a new tab. |
| `:q`, `:close` | Close the tab. |
| `:qa`, `:quit`, `:exit` | Quit. |
| `:tab N` | Go to tab N. |
| `:tabnext`, `:tabprev` | Go to the next and the previous tab. |
| `:tabfirst`, `:tablast` | Go to the first and the last tab. |
| `:w FILE` | Write the document to FILE as JSON, but not over a file that exists. |
| `:w! FILE` | Write the document to FILE as JSON, over a file that exists. |
| `:ws FILE` | Write the text of the version on screen to FILE, but not over a file that exists. |
| `:ws! FILE` | Write the text of the version on screen to FILE, over a file that exists. |
| `:history` | List the versions in the history tab. |
| `:format FORMAT` | Read the tab's text again as FORMAT. |
| `:mode data`, `:mode line` | Switch to data mode or line mode. |
| `:depth N` | Open the first N levels, and fold every container below them. |
| `:expand` | Unfold the focused node and its siblings, and everything inside them. |
| `:collapse` | Fold everything, and go to the first row. |
| `:N`, `:line N` | Go to row N. |
| `:reload`, `:e!` | Read the file again now. |
| `:watch on`, `:watch off` | Start or stop watching the file. |
| `:source` | Show the source view. |
| `:error` | Show the parse error report full size. |
| `:cd DIR` | Make DIR the explorer's root. DIR is relative to the current root. In a document's tab, open DIR in a new explorer tab. |
| `:explore [DIR]` | Open DIR, or the current directory, in a new explorer tab. |
| `:set SETTING` | Change a setting, from the Settings list. |
| `:help` | Show this help. |

## Settings

Each follows `:set`, and one `:set` takes several.

| Keys | Does |
|---|---|
| `number`, `nonumber`, `number!` | Number the rows, or stop, or switch between the two. `nu` is the short form. |
| `relativenumber`, `norelativenumber`, `relativenumber!` | Number each row by its distance from the focus, or stop, or switch between the two. `rnu` is the short form. |
| `so=N` | Keep N rows between the focus and the edge of the screen. |
| `indent=N`, `sw=N` | Indent N spaces a level, at most 16. |
| `ascii`, `noascii` | Draw the fold markers as `v` and `>`, or as `▼ ▽ ▶ ▷`. |
| `hidden`, `nohidden`, `hidden!` | Show dot-files in the explorer, or hide them, or switch between the two. |
| `watch`, `nowatch` | Start or stop watching the file. |
| `changes`, `nochanges`, `changes!` | Mark what each version changed, or stop, or switch between the two. |
| `history=N` | Keep up to N versions of each file, and fewer of a large one. The version on screen and the newest always stay. |
| `mode=data`, `mode=line` | Switch to data mode or line mode. |
| `depth=N` | Open the first N levels, and fold every container below them. |

## Typing a command or a pattern

| Keys | Does |
|---|---|
| `Enter` | Run the command, or search for the pattern. |
| `Esc`, `Ctrl+C` | Leave without running the command or the search. |
| `Backspace`, `Ctrl+H`, `Delete` | Delete the character before or under the cursor. |
| `←` `→`, `Ctrl+B` `Ctrl+F` | Move the cursor a character. |
| `Home` `End`, `Ctrl+A` `Ctrl+E` | Move the cursor to the start or the end. |
| `Ctrl+U`, `Ctrl+K`, `Ctrl+W` | Delete to the start, to the end, or the word before the cursor. |

## This help, the error report, and printed text

Any other key goes back to the document.

| Keys | Does |
|---|---|
| `j` `k`, `↓` `↑` | Scroll a line. |
| `Ctrl+D` `Ctrl+U`, `Ctrl+F` `Ctrl+B`, `PgDn` `PgUp` | Scroll a page. |
| `g` `G`, `Home` `End` | Go to the first and the last line. |
| `h` `l`, `←` `→` | Pan a line wider than the screen. |
