# Editing Text

*Lx* keeps common editing actions close at hand.

## Save and undo

| Shortcut | Action |
| --- | --- |
| Ctrl+S | Save |
| Ctrl+Shift+S | Save As |
| Ctrl+Z | Undo |
| Ctrl+Shift+Z | Redo |

## Select text

You can select exact characters, complete words, whole lines, or a rectangular block. Mouse selection starts as soon as you press the button; you don't have to release it first.

### Click and drag

| Gesture | What happens |
| --- | --- |
| Click | Places the cursor where you clicked and clears the current selection |
| Drag | Selects the exact characters you drag across |
| Shift+click | Extends the current selection from its existing anchor |
| Double-click | Selects a complete word token or divider token |
| Double-click, then drag | Selects complete word or divider tokens at both ends of the dragged range |
| Triple-click | Selects the complete logical line |
| Triple-click, then drag | Selects complete logical lines |

Keep clicking quickly and *Lx* alternates between the double-click selection and the complete line: the fourth click repeats the token selection, the fifth selects the line again, and so on. Pause or move away before clicking and the sequence starts over with an ordinary single click.

A complete line includes every wrapped part of that line, but not its final line break. Deleting a triple-clicked line therefore leaves an empty line instead of joining the surrounding lines.

For mouse selection, a word token is an uninterrupted sequence containing neither whitespace nor a character from `config.word_dividers`. Underscores belong to a word token by default; hyphens don't. Adjacent divider characters form a valid divider token of their own, so `!---!4343this` separates into `!---!` and `4343this`, while `!this` separates into `!` and `this`. Double-clicking the first whitespace position after a word token selects that token on its left; whitespace farther away has no token to select.

Shift only extends a selection with a single click. Shift+double-click and later clicks don't switch into word or line selection.

### Multiple cursors and column selection

The configurable multi-cursor modifier is **Alt** by default:

| Gesture | What happens |
| --- | --- |
| Alt+click | Adds or removes a cursor at that position |
| Alt+Shift+drag | Makes a rectangular column selection |
| Alt+middle-click | Adds or removes the complete word at that position as another selection |

Change `config.multi_cursor_modifier` if you prefer **Ctrl** or **Command**. The same three gestures then use that key instead of **Alt**. Set `config.enable_multi_cursor = false` to turn these gestures off.

If you already have selected text, modifier+click reduces the primary selection to its cursor before adding or removing another cursor. Press **Escape** to return to one cursor.

### Other mouse buttons and editor areas

- Drag with the middle mouse button to pan the document in any direction.
- Ctrl+middle-click resets document zoom. If **Ctrl** is your multi-cursor modifier, it toggles the clicked word instead.
- Right-click has no built-in editor menu. Unless you assign it a command, it follows the ordinary text-selection path.
- Click a scrollbar track to jump there, or drag its handle for direct scrolling. Scrollbar clicks don't move the text cursor.
- When file-reference links are visible, their Ctrl+click or Command+click takes priority over text selection. See [File References](file_references.md#following-references-with-the-mouse).

Mouse buttons can be assigned to commands with `lclick`, `mclick`, `rclick`, `xclick1`, and `xclick2`. A matching command takes priority over the built-in text behavior. See [Keyboard Shortcuts](keymap.md#key-names).

### Keyboard selection

Hold **Shift** while moving the cursor to select with the keyboard.

Useful selection shortcuts include:

| Shortcut | Action |
| --- | --- |
| Ctrl+A | Select everything |
| Ctrl+L | Select whole lines |
| Ctrl+Shift+Left | Select to the previous word |
| Ctrl+Shift+Right | Select to the next word |
| Shift+Home | Select to the start of the line |
| Shift+End | Select to the end of the line |

## Work with lines

| Shortcut | Action |
| --- | --- |
| Ctrl+Y | Delete the selected lines |
| Ctrl+Shift+D | Duplicate the selected lines |
| Ctrl+J | Join lines |
| Tab | Indent |
| Shift+Tab | Unindent |
| Ctrl+/ | Add or remove line comments |

Most line actions also work when you have only a cursor and no selection.

## Indent text

Press **Tab** to indent and **Shift+Tab** to unindent. *Lx* can insert spaces or literal tab characters, and it detects the likely choice separately for each document.

The status bar shows the active setting as `Spaces: N` or `Tabs: N`. An added `*` means the size is automatic.

- Click the status item to cycle through automatic detection and the default sizes 2, 4, and 8.
- Middle-click it to re-scan the document and return both the type and size to automatic detection.
- Hold **Alt** while clicking to switch between spaces and tabs without rewriting the file.

Changing what **Tab** inserts is not the same as converting existing indentation. See [Indentation](indentation.md) for automatic detection, status controls, conversion commands, and settings.

## Use more than one cursor

- Press **Ctrl+Alt+Up** or **Ctrl+Alt+Down** to add a cursor on the line above or below.
- Press **Alt+D** to select the next occurrence of the current word or selection.
- Press **Shift+Alt+I** to place a cursor at the end of every selected line.
- Press **Escape** to remove extra cursors.

Typing and editing then apply at every cursor.

## Wrap long lines

Press **Alt+Z** to turn word wrapping on or off. You can also click **Wrap** or **No Wrap** in the status bar.

Wrapping changes how a long line fits on screen. It does not add line breaks to the file.

## Format marked-up text

*Lx* can add or remove markers for bold, italic, underline, and other supported formats. It can also surround selected text as you type.

See [Formatting and Surrounding Text](format_shortcuts.md) and [Auto Surround](auto_surround.md).
