> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tablepro.app/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` chord passes through in any mode, so `Cmd+Enter` still runs the query.

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

![Vim mode badge](https://mintcdn.com/ngquct/sezpSJY0oLylJ5LP/images/vim-mode-badge.png?fit=max\&auto=format\&n=sezpSJY0oLylJ5LP\&q=85\&s=ec8687ce01d4a4bf2fc9e91594d59675)

Mode badge in the SQL editor

## Modes

| Mode | How to enter |
| - | - |
| Normal | `Esc`, `Ctrl+[` |
| 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. The arrow keys do the same |
| `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 |
| `Enter` `+` | First non-blank of the next line |
| `-` | First non-blank of the line before |
| `H` `M` `L` | Top, middle, bottom of view. `3H` is the third line from the top, `3L` from the bottom |
| `gj` `gk` | The same lines as `j` `k`. Wrapped display lines have no motion of their own |
| `%` | Matching `()`, `[]`, `{}` |
| `50%` | The line halfway through the text |

### 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. `Forward Delete` is `x` |
| `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.

Every motion works after an operator: `d%` deletes through the matching bracket, `d}` to the end of the paragraph, `d'a` the lines up to mark `a`, and `d/pattern` `Enter` up to the next match. `cw` changes to the end of the word. `Esc` drops a command still being typed, with its count and register.

Yank, delete, and change all write to the system clipboard, except through the black-hole register `"_`.

## 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. `p` then keeps the replaced text in `"`, and `P` leaves the registers as they were.

## Registers

Prefix a command with `"` and the register's name to pick one.

| 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 |
| `"_` | Nothing. A yank or delete through it leaves every other register and the clipboard as they were |

`"ayy` stores a line in `a`. `"ap` pastes it back later. `"_dd` deletes a line and keeps what you yanked last ready for `p`.

## 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 |

A mark keeps its line and column. Lines added or removed above it move it, a join carries it along, deleting its line removes it, and undo puts it back. Each query tab keeps its own marks.

## 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

Outside insert mode, a `Ctrl` letter goes to vim, never to the editor's own binding:

| Keys | Normal mode | Visual mode |
| - | - | - |
| `Ctrl+D` `Ctrl+U` | Down, up half the visible lines. With a count, that many lines | Moves the end of the selection half the visible lines |
| `Ctrl+F` `Ctrl+B` | Down, up one screen | Moves the end of the selection one screen |
| `Ctrl+A` `Ctrl+X` | Add, subtract 1 from the number under or after the cursor. `5 Ctrl+A` adds 5 | Nothing |
| `Ctrl+R` | Redo | Nothing |
| `Ctrl+H` `Ctrl+N` `Ctrl+P` | Same as `h`, `j`, `k` | Same as `h`, `j`, `k` |

Any other `Ctrl` letter does nothing. That includes `Ctrl+E` and `Ctrl+Y`, which like `zt`, `zz` and `zb` are read and discarded: the view scrolls only to follow the cursor. `Ctrl+Space` still opens completions, and `Ctrl+Tab` and `Ctrl+Shift+Tab` still [switch tabs](https://docs.tablepro.app/features/tabs.md#switching-tabs). To leave the editor from the keyboard, use a command under **View > Focus**. A shortcut of `Ctrl` and a letter assigned in **Settings > Keyboard** does not fire from the SQL editor outside insert mode.

In insert and replace mode, vim takes these and leaves every other `Ctrl` combination to the editor:

| Keys | Action |
| - | - |
| `Esc` `Ctrl+[` | Back to normal mode |
| `Ctrl+W` | Delete the word before the cursor |
| `Ctrl+U` | Delete back to the start of the line |
| `Ctrl+T` `Ctrl+D` | Indent, outdent the line |

`Ctrl+H` is the editor's own backspace in insert mode, so it deletes a selection the way `Delete` does. In replace mode vim takes it, and like `Delete` it restores the character you overwrote.

## Option keys

An `Option` chord outside insert mode is read as the character it types. On a keyboard layout where `Option` types `[` or `@`, such as German, those work as vim commands, and a character vim has no use for, such as the non-breaking space from `Option+Space`, does nothing. A dead key such as `Option+E` on the US layout does nothing outside insert mode.

In insert mode, `Option` types as usual. In replace mode, the character it types overwrites the one under the cursor.

## 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` or `Ctrl+[` goes back to normal mode. Apart from the insert-mode [control keys](#control-keys), what you type goes to the editor as usual.

## Switch tabs

| Keys | Goes to |
| - | - |
| `gt` | Next tab, wrapping from the last to the first |
| `gT` | Previous tab, wrapping from the first to the last |
| `{N}gt` | Tab N |
| `{N}gT` | N tabs back |
| `:tabn[ext]` | Next tab |
| `:tabn[ext] {N}` | Tab N |
| `:tabn[ext] +{N}` `:tabn[ext] -{N}` | N tabs forward, N tabs back |
| `:tabp[revious] [N]` `:tabN[ext] [N]` | Previous tab, or N tabs back |

The part in brackets is optional, so `:tabn`, `:tabne` and `:tabnext` are one command. Tabs are counted along the strip, the same tabs `Cmd+1` through `Cmd+9` count, and a number past the last one selects the last tab. `gt` and `gT` work in normal mode only.

## Command line

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

`/` and `?` are search, and `:tabnext`, `:tabprevious` and `:tabNext` [switch tabs](#switch-tabs). 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`.

`Delete` and `Ctrl+H` erase the last character of the command. The arrow keys and the other `Ctrl` letters do nothing while you type one.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.