# Command Line

Open files, choose how they appear, or set text options when starting *Lx*.

## Basic use

Open one file:

```cli
lx notes.txt
```

Open several files:

```cli
lx notes.txt todo.md image.png
```

A single startup file stays temporary until you edit or pin it. Selecting another file in the Browser can replace it.

Pin only the next file:

```cli
lx notes.txt --pin todo.md image.png
```

Here, only `todo.md` is pinned. Repeat `--pin` before each file you want to keep.

Open command-line help inside *Lx*:

```cli
lx --help
```

You can also use `-h`, `-?`, or `/?`.

## Choose how a file opens

Use these options for every file in the same command:

| Option | Shortcut | Opens as |
| --- | --- | --- |
| `--edit` | `-e` | Editable text |
| `--view` | `-v` | Read-only text |
| `--preview` | `-p` | A rendered preview, when available |
| `--bytes` | `-b` | Raw bytes |
| `--hex` | `-x` | Hexadecimal bytes |

Preview a Markdown file:

```cli
lx --preview readme.md
```

Open an image as raw hex:

```cli
lx --hex photo.jpg
```

The option may come before or after the file:

```cli
lx report.md --view
```

## Extract or unpack first

Some files hold other content. *Lx* can extract or unpack that content before showing it.

Extract readable text from an Office document:

```cli
lx --extract report.docx
```

Extract it and open the result as read-only text:

```cli
lx --extract --view report.docx
```

Extract it and inspect the result as hex:

```cli
lx --extract --hex report.docx
```

Extract it, treat the result as Markdown, and open it read-only:

```cli
lx --extract --format md --view report.docx
```

Unpack an Ableton Live Set and preview the resulting XML:

```cli
lx --unpack --preview song.als
```

| Option | Shortcut | Action |
| --- | --- | --- |
| `--extract` | `-ex` | Extract readable content |
| `--unpack` | `-un` | Unpack stored content |
| `--action NAME` | `-ac NAME` | Use a named action |
| `--handler NAME` | `-ha NAME` | Use a named file handler |
| `--source-format NAME` | `-sf NAME` | Set the format of the original file |

When extracting or unpacking, `--format` applies to the result. Use `--source-format` only when the original file needs a forced format.

An explicit edit, view, preview, bytes, or hex choice also applies to the result.

## Text settings

Open UTF-16 text:

```cli
lx --encoding utf16 notes.txt
```

Open text with a legacy codepage:

```cli
lx --codepage cp437 artwork.txt
```

Open a file with CRLF line endings and a tab size of 8:

```cli
lx --newline crlf --tab-size 8 source.txt
```

| Option | Shortcut | Meaning |
| --- | --- | --- |
| `--encoding NAME` | `-en NAME` | Select a UTF text encoding |
| `--codepage NAME` | `-cp NAME` | Select a legacy codepage |
| `--tab-size NUMBER` | `-t NUMBER` | Set the tab and indentation size |
| `--newline NAME` | `-nl NAME` | Use `lf`, `crlf`, or automatic line endings |
| `--defaults` | `-D` | Return to configured defaults |

Use `--codepage none` to clear a codepage choice without changing the main text encoding.

## New documents

Create an empty document:

```cli
lx --new
```

Create one with a name and Markdown format:

```cli
lx --name draft.md --format md --new
```

| Option | Shortcut | Meaning |
| --- | --- | --- |
| `--new` | `-n` | Create an empty document |
| `--name FILE` | `-N FILE` | Name the next new document |
| `--format NAME` | `-f NAME` | Set the final document format |

## Split files

Open two files side by side:

```cli
lx left.txt --pane-right right.txt
```

Use `--pane-left`, `--pane-right`, `--pane-up`, or `--pane-down` to choose the split direction.

## Reset options

Options continue to apply to later files in the same command. Use `--defaults` when later files should return to your configured defaults.

```cli
lx --view first.txt second.txt --defaults third.txt
```
