# Multiple cursors in Skink: Ctrl+D, Alt+click and more

> Edit in several places at once in Skink: Ctrl+D selects the next match, Alt+Shift+Up/Down add cursors above and below, Alt+click adds one, Esc goes back to one.

Source: https://skink.cc/editing/multiple-cursors/

Press Ctrl+D to select the word under the cursor, then press it again to add a cursor at the next match. Type, and every cursor types. Esc goes back to a single cursor.

This works like Sublime Text and VS Code, with Micro's action names.

## Multiple cursor keys

| Key | Typed command | Does |
|---|---|---|
| Ctrl+D or Alt+N | `:addcursor` | Select the word; again: add a cursor at the next match |
| Alt+X | `:skipcursor` | Skip this match and select the next one |
| Alt+Shift+↑ / ↓ | `:cursorabove` / `:cursorbelow` | Add a cursor on the line above / below |
| Ctrl+Alt+↑ / ↓ | same | An alternative binding for the same |
| Alt+click | | Add a cursor, or remove the one under the mouse |
| Esc or Alt+C | `:onecursor` | Back to one cursor |

The status line shows **×N** while you have N cursors.

**Alt chords not arriving?:**
On macOS or inside tmux, Alt+Shift+arrow chords often get lost. Press Ctrl+E and type the command instead, for example `cursorbelow`. See [Typed commands](https://skink.cc/editing/typed-commands/).

## What happens at every cursor

- Typing, deleting, moving, indenting and moving lines (Alt+↑ / ↓).
- Case changes, join, sort and trim (`:UpperCase`, `:LowerCase`, `:TitleCase`, `:JoinLines`, `:SortLines`, `:TrimTrailingWhitespace`).
- One undo (Ctrl+Z) undoes the change at all cursors.

## Copy and paste with several cursors

- Copy with N cursors puts one line per cursor on the clipboard.
- Pasting N lines into N cursors gives each cursor its own line.

So you can copy five values from five places and paste them into five other places in one go.

## Examples

### Rename a variable within a function

Put the cursor on the name and press Ctrl+D once to select it. Press it again for each use you want, and Alt+X to skip a match you do not want. Type the new name.

For a rename across files that understands your code, use the language server instead: Alt+Shift+R. See [Refactoring](https://skink.cc/code/refactoring/).

### Add a comma at the end of ten lines

Put the cursor on the first line and press Alt+Shift+↓ nine times. Press End, then type `,`.

### Edit every match in the file at once

For a plain replace-all, the find bar is quicker: Ctrl+F, type, Tab, type the replacement, Enter. See [Find and replace](https://skink.cc/editing/find-and-replace/).

## Bind the multiple cursor actions

The actions use Micro's names, so they can be bound in `bindings.json`:

| Action | Does |
|---|---|
| `SpawnMultiCursor` | Select the word, then add a cursor at the next match |
| `SpawnMultiCursorUp` / `SpawnMultiCursorDown` | Add a cursor above / below |
| `SkipMultiCursor` | Skip this match and select the next |
| `RemoveMultiCursor` | Remove the newest cursor |
| `RemoveAllMultiCursors` | Back to a single cursor |

For example, to remove the newest cursor with Alt+Shift+X (Micro's format writes Shift as a capital letter):

```json
{ "Alt-X": "RemoveMultiCursor" }
```

See [Key bindings](https://skink.cc/customize/keybindings/).
