> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-docs-fix-500-query-results.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Vim Mode

> Vim motions, text objects, registers, marks, and search inside the SQL editor

Vim mode is scoped to the SQL editor. The data grid, the find field and every other control in the window keep their own keys, and a `Cmd` or `Option` chord passes through in any mode, so `Cmd+Enter` still runs the query.

Turn it on in **Settings > Editor > Vim mode**, which is also the only way to turn it off: there is no `:set`. A badge next to the editor shows the current mode.

<Frame caption="Mode badge in the SQL editor">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/0TDhsORsgVLO0zL5/images/vim-mode-badge.png?fit=max&auto=format&n=0TDhsORsgVLO0zL5&q=85&s=2583065d0826fe0ce9ac907f31bad7c2" alt="Vim mode badge" width="1560" height="960" data-path="images/vim-mode-badge.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/0TDhsORsgVLO0zL5/images/vim-mode-badge-dark.png?fit=max&auto=format&n=0TDhsORsgVLO0zL5&q=85&s=26280dd9ab53e7880ab89c3a62d45308" alt="Vim mode badge" width="1560" height="960" data-path="images/vim-mode-badge-dark.png" />
</Frame>

## Modes

| Mode         | How to enter                                           |
| ------------ | ------------------------------------------------------ |
| Normal       | `Esc`                                                  |
| Insert       | `i`, `I`, `a`, `A`, `o`, `O`, `s`, `S`, `c`, `C`, `gi` |
| Replace      | `R`                                                    |
| Visual       | `v`                                                    |
| Visual Line  | `V`                                                    |
| Command line | `:`, `/`, `?`                                          |

`gi` puts you back where you last left insert.

## Move the cursor

### Characters

| Key             | Goes to                 |
| --------------- | ----------------------- |
| `h` `j` `k` `l` | Left, down, up, right   |
| `0`             | Start of line           |
| `^` `_`         | First non-blank on line |
| `$`             | End of line             |

### Words

| Key         | Goes to                             |
| ----------- | ----------------------------------- |
| `w` `b` `e` | Next word, prev word, word end      |
| `W` `B` `E` | Same, whitespace-only word boundary |
| `ge` `gE`   | Prev word end, prev WORD end        |

### Lines

| Key         | Goes to                                                                      |
| ----------- | ---------------------------------------------------------------------------- |
| `gg`        | First line                                                                   |
| `G`         | Last line                                                                    |
| `5G`        | Line 5                                                                       |
| `H` `M` `L` | Top, middle, bottom of view                                                  |
| `gj` `gk`   | The same lines as `j` `k`. Wrapped display lines have no motion of their own |
| `%`         | Matching `()`, `[]`, `{}`                                                    |

### Find a character

| Key     | Goes to                             |
| ------- | ----------------------------------- |
| `f{c}`  | Next `{c}` on this line             |
| `F{c}`  | Prev `{c}` on this line             |
| `t{c}`  | Just before next `{c}`              |
| `T{c}`  | Just after prev `{c}`               |
| `;` `,` | Repeat last find, reverse last find |

### Sentences and paragraphs

| Key       | Goes to                              |
| --------- | ------------------------------------ |
| `(` `)`   | Prev sentence, next sentence         |
| `{` `}`   | Prev blank line, next blank line     |
| `[[` `]]` | Prev `{`-at-col-0, next `{`-at-col-0 |

Counts work: `3w` moves three words, `5j` moves five lines down.

## Edit

| Key                     | Action                                      |
| ----------------------- | ------------------------------------------- |
| `d{m}`                  | Delete (with motion)                        |
| `c{m}`                  | Change (delete then enter insert)           |
| `y{m}`                  | Yank                                        |
| `dd` `cc` `yy`          | Same on the whole line                      |
| `D` `C` `Y`             | Same as `d$`, `c$`, `yy`                    |
| `x` `X`                 | Delete one char under, one before cursor    |
| `s` `S`                 | Replace one char or whole line, then insert |
| `r{c}`                  | Replace one char with `{c}`, stay in normal |
| `~`                     | Toggle case under cursor                    |
| `g~{m}` `gu{m}` `gU{m}` | Toggle, lower, upper with motion            |
| `g~~` `guu` `gUU`       | Same on the whole line                      |
| `>>` `<<`               | Indent, outdent line                        |
| `>{m}` `<{m}`           | Indent, outdent with motion                 |
| `J`                     | Join next line with a space                 |
| `gJ`                    | Join next line, no space                    |

`2d3w` deletes six words. `3yy` yanks three lines. `5>>` indents five lines.

Yank, delete, and change all write to the system clipboard.

## Text objects

Use after `d`, `c`, `y`, or in visual mode.

| Object                 | Inside             | Around             |
| ---------------------- | ------------------ | ------------------ |
| Word                   | `iw`               | `aw`               |
| WORD                   | `iW`               | `aW`               |
| `"` `'` `` ` `` string | `i"` `i'` `` i` `` | `a"` `a'` `` a` `` |
| `(` `)` parens         | `i(` `ib`          | `a(` `ab`          |
| `{` `}` braces         | `i{` `iB`          | `a{` `aB`          |
| `[` `]` brackets       | `i[`               | `a[`               |
| `<` `>` angles         | `i<`               | `a<`               |
| HTML tag               | `it`               | `at`               |
| Paragraph              | `ip`               | `ap`               |

`ciw` rewrites the current word. `da"` removes a quoted string and its trailing space. `yip` copies the current paragraph.

## Paste

| Key  | Action                                             |
| ---- | -------------------------------------------------- |
| `p`  | After cursor (or below the line for linewise yank) |
| `P`  | Before cursor (or above the line)                  |
| `3p` | Paste three times                                  |

In visual mode, `p` and `P` replace the selection with the register.

## Registers

Prefix with `"{a-z}` to pick a register.

| Register    | Holds                               |
| ----------- | ----------------------------------- |
| `"`         | Last yank or delete                 |
| `"a` … `"z` | Named, overwrite                    |
| `"A` … `"Z` | Same, append                        |
| `"0`        | Last yank only                      |
| `"1` … `"9` | Delete ring, rotates on each delete |

`"ayy` stores a line in `a`. `"ap` pastes it back later.

## Marks

| Key               | Action                                     |
| ----------------- | ------------------------------------------ |
| `m{a-z}`          | Set mark                                   |
| `` `{a-z} ``      | Jump to exact mark                         |
| `'{a-z}`          | Jump to first non-blank of the mark's line |
| `` `< `` `` `> `` | Start, end of last visual selection        |
| `''` ` ` \`\`     | Back to position before the last jump      |

Marks shift when you insert or delete text before them.

## Search

| Key                | Action                                    |
| ------------------ | ----------------------------------------- |
| `/pattern` `Enter` | Forward search                            |
| `?pattern` `Enter` | Backward search                           |
| `n` `N`            | Next, previous match                      |
| `*` `#`            | Search word under cursor, forward or back |

The pattern is a literal, case-sensitive substring, not a regex. Searches wrap around.

## Repeat and undo

| Key      | Action                      |
| -------- | --------------------------- |
| `.`      | Repeat last change          |
| `u`      | Undo                        |
| `U`      | Undo all edits on this line |
| `Ctrl+R` | Redo                        |

`5.` repeats the last change five times.

## Macros

| Key      | Action                          |
| -------- | ------------------------------- |
| `q{a-z}` | Start recording into a register |
| `q`      | Stop recording                  |
| `@{a-z}` | Play back                       |
| `@@`     | Play back the last macro        |
| `3@a`    | Play three times                |

A macro that calls itself stops after 50 rounds.

## Control keys

`Ctrl+R` in normal mode is the only control combination vim mode intercepts, and it redoes. Every other one reaches the editor and gets the editor's own binding, so these vim meanings are not available:

| Keys                                                  | What you do not get                                                                                                                       |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `Ctrl+D` `Ctrl+U` `Ctrl+F` `Ctrl+B` `Ctrl+E` `Ctrl+Y` | Scrolling. `Ctrl+D` deletes the character after the cursor and `Ctrl+E` goes to the end of the paragraph instead                          |
| `Ctrl+A` `Ctrl+X`                                     | Increment and decrement the number under the cursor. `Ctrl+A` goes to the start of the paragraph instead                                  |
| `Ctrl+W` `Ctrl+U` `Ctrl+T` `Ctrl+D`                   | Insert-mode delete word, delete to line start, indent, outdent. `Ctrl+H` still backspaces, through the editor's binding rather than vim's |

`zt`, `zz` and `zb` are read and discarded, so there is no way to move the viewport from the keyboard at all.

## Visual mode

Motions extend the selection. Then:

| Key         | Action                             |
| ----------- | ---------------------------------- |
| `d` `x`     | Delete                             |
| `c`         | Delete and insert                  |
| `y`         | Yank                               |
| `J` `gJ`    | Join lines                         |
| `~` `u` `U` | Toggle, lower, upper case          |
| `r{c}`      | Replace each char with `{c}`       |
| `o`         | Move cursor to the other end       |
| `I` `A`     | Insert at start, end of selection  |
| `gv`        | Reselect the last visual selection |

Indent and outdent work in normal mode only (`>>`, `<<`, `>{m}`, `<{m}`).

## Insert mode

`Esc` goes back to normal mode. Nothing else is intercepted while you type; see [Control keys](#control-keys).

## Command line

| Command | Action                |
| ------- | --------------------- |
| `:w`    | Run the current query |
| `:q`    | Close the tab         |

`/` and `?` are search. Every other `:` command is parsed and ignored, `:wq`, `:x` and `:set` among them. `:10` does not jump to line 10 either; use `10G` or `10gg`.
