# Text Tools

*Lx* includes commands for cleaning, rearranging, converting, and formatting text.

Open the [Command Palette](command_palette.md) with **Ctrl+Shift+P**, then enter one of the command names below.

## Which lines are changed

When you select text, line tools change the selected lines.

Without a selection, they change the whole document.

The changes are normal edits. Use **Ctrl+Z** if you want to undo them.

## Trim spaces

| Command | Action |
| --- | --- |
| `lines:trim-trailing-whitespaces` | Remove spaces and tabs at line ends |
| `lines:trim-leading-whitespaces` | Remove spaces and tabs at line starts |
| `lines:trim-whitespaces` | Remove both |

The supplied Alpha settings bind **Alt+Delete** to trailing-space removal.

Trailing spaces are also cleaned when a document is saved. The active line is left alone when the cursor is at its end.

## Sort and remove duplicates

| Command | Action |
| --- | --- |
| `lines:sort` | Sort with uppercase and lowercase kept distinct |
| `lines:sort-caseless` | Sort without treating case as different |
| `lines:unique` | Sort and remove exact duplicate lines |
| `lines:unique-caseless` | Sort and remove duplicates regardless of case |
| `lines:reverse` | Reverse the line order |
| `lines:shuffle` | Put lines into a random order |

The two `unique` commands sort the result as part of removing duplicates.

## Clean empty lines

| Command | Action |
| --- | --- |
| `lines:remove-empty` | Remove every empty or whitespace-only line |
| `lines:collapse-empty` | Reduce each group of empty lines to one |

## Wrap, split, and merge lines

| Command | Action |
| --- | --- |
| `lines:wrap` | Wrap selected or current lines at the usual width |
| `lines:wrap-at-cursor` | Use the cursor column as the wrapping width |
| `lines:wrap-all` | Wrap the whole document |
| `lines:split` | Split selected or current lines at a fixed width |
| `lines:split-at-cursor` | Use the cursor column as the splitting width |
| `lines:split-all` | Split the whole document |
| `lines:merge` | Merge selected or current lines |
| `lines:merge-blocks` | Merge each group separated by empty lines |
| `lines:merge-all` | Merge the whole document into one line |
| `lines:normalize-paragraphs` | Merge and rewrap paragraph blocks |

The usual width comes from `config.alignblock_default_width`, the first ruler, `config.line_limit`, or 80 columns.

The supplied shortcuts are:

| Shortcut | Action |
| --- | --- |
| Ctrl+Shift+W | Wrap lines |
| Ctrl+Shift+M | Merge lines |
| Ctrl+Shift+Alt+Enter | Wrap at the cursor column |

## Change letter case

Case commands change each selection, or the word below each cursor:

| Command | Action |
| --- | --- |
| `case:lower` | Change text to lowercase |
| `case:upper` | Change text to uppercase |
| `case:title` | Capitalize every word |
| `case:capital` | Capitalize the first non-space character |
| `case:cameltitlesnake` | Cycle a name through camelCase, TitleCase, and snake_case |

| Shortcut | Action |
| --- | --- |
| Ctrl+Shift+L | Lowercase |
| Ctrl+Shift+U | Uppercase |
| Ctrl+Shift+T | Title case |
| F6 | Cycle camelCase, TitleCase, and snake_case |

`case:capital` has no supplied shortcut.

## Add or remove comments

Comment choices depend on the active format:

| Command | Action |
| --- | --- |
| `comment:toggle-line` | Add or remove line comments |
| `comment:toggle-block` | Add or remove a block comment |
| `comment:toggle-inline-block` | Add or remove an inline block comment |
| `comment:toggle-guard` | Add or remove a guard-style comment |
| `comment:toggle-smart` | Choose a suitable comment style |
| `comment:uncomment` | Remove supported comment markers |

Common shortcuts are **Ctrl+/** for line comments, **Alt+C** for smart comments, and **Ctrl+Alt+C** for block comments.

## Format JSON and XML

| Command | Action |
| --- | --- |
| `tidyjson:format` | Format JSON or JSON Lines automatically |
| `tidyjson:format-single` | Format exactly one JSON value |
| `tidyjson:format-lines` | Turn JSON Lines into one formatted array |
| `tidyjson:format-sorted` | Format and sort object keys |
| `tidyjson:format-single-sorted` | Format one value and sort its keys |
| `tidyjson:format-lines-sorted` | Format JSON Lines and sort keys |
| `tidyjson:minimize` | Remove unnecessary JSON spacing |
| `tidyxml:format` | Format XML |
| `tidyxml:minimize` | Remove unnecessary XML spacing |

The supplied Alpha settings bind **Ctrl+Alt+J** to automatic JSON formatting and **Ctrl+Shift+Alt+J** to JSON minimization.

The XML formatter does not preserve comments, processing instructions, or CDATA sections. *Lx* warns before using it.

## Align separated text

Run `tabularize:tabularize` to enter a delimiter and align the selected rows around it.

CSV commands are available for `.csv` files:

| Command | Action |
| --- | --- |
| `csv:align` | Open an aligned text copy in a new tab |
| `csv:align-inplace` | Align the selected rows or whole CSV document |
| `csv:convert-to-tsv` | Open a TSV copy in a new tab |

These commands are available for `.tsv` files:

| Command | Action |
| --- | --- |
| `tsv:align` | Open an aligned text copy in a new tab |
| `tsv:align-inplace` | Align the selected lines or whole TSV document |
| `tsv:convert-to-csv` | Open a CSV copy in a new tab |

Alignment keeps empty cells, including empty cells at the end of a row.

## Encode HTML characters

Without a selection, these commands change the current line:

| Command | Action |
| --- | --- |
| `html:encode` | Encode `&`, `<`, `>`, quotes, and apostrophes |
| `html:encode-full` | Encode every character with a known HTML name |
| `html:decode` | Turn HTML character references back into text |

## Quote and unquote text

| Command | Action |
| --- | --- |
| `string:quote` | Quote text using the active format's main quote style |
| `string:unquote` | Remove a recognized pair of quotes |
| `string:toggle-quote` | Add quotes, or remove them when already present |

The Command Palette also lists format-specific choices such as `string:quote:<profile>`.

## Create number sequences

| Command | Action |
| --- | --- |
| `arithmetic:number` | Number selected lines from 1 |
| `arithmetic:number-start-step` | Ask for the starting number and step |
| `arithmetic:apply` | Apply an expression to selected text or lines |

`arithmetic:number` also accepts choices such as:

```text
arithmetic:number(start: 10, step: 5)
```

## Extract readable text from RTF

These commands are available while an `.rtf` file is open as editable text:

| Command | Action |
| --- | --- |
| `rtf:strip` | Open a plain-text copy in a new tab |
| `rtf:strip-inplace` | Replace the selected lines or whole document with plain text |
| `rtf:strip-to-markdown` | Open a Markdown copy in a new tab |

The Markdown conversion keeps useful basic formatting, lists, links, and Unicode text where possible.

See [Formatting and Surrounding Text](format_shortcuts.md) and [Auto Surround](auto_surround.md) for adding Markdown and other format markers.
