# Text Encodings and Codepages

An encoding tells *Lx* how file bytes become readable text.

## UTF text

*Lx* recognizes:

- UTF-8
- UTF-8 with a byte-order mark
- UTF-16 little-endian
- UTF-16 big-endian

*Lx* normally detects these automatically.

## Legacy codepages

Older text files may use a codepage such as Windows-1252 or CP437 instead of Unicode.

*Lx* tries automatic detection first. If the file is not valid UTF text and no format gives a better answer, `config.fallback_codepage` is used. Its default is `cp1252`.

Change it in your settings:

```lua
local config = require("core.config")

config.fallback_codepage = "cp1252"
```

## Status bar

The status bar shows the file's text encoding as one label:

- Unicode files show `UTF-8`, `UTF-8 BOM`, or `UTF-16`.
- Legacy files show their codepage, such as `CP437`.

A codepage label does not mean the file is ANSI art. It only records how legacy bytes were read.

## Fix text that looks wrong

Run `doc:set-codepage` from the command palette.

Choose the codepage that matches the file. *Lx* reopens a saved file from disk with that choice.

Save or discard changes first. *Lx* will not reinterpret unsaved edits.

## Force an encoding when opening

Use the command line when automatic detection is wrong:

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

For a legacy codepage:

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

Use `--codepage none` to clear the codepage choice.

See [Command Line](cli.md) for all opening options.

## Line endings

Line endings are separate from text encoding.

The status bar shows `LF`, `CRLF`, or `CR`. Click it to switch between LF and CRLF, or run `doc:toggle-line-ending`.
