Skip to content

Key bindings and vim mode ​

The TUI's keys work out of the box, and you can change any of the app-wide ones. You can also edit SQL with vim keys.

To see every key in quarry itself, press F1 and type to filter, for example run, ctrl or vim. Each rebindable action shows its name on the right. That name is what you write in the config.

Change a key ​

Add a [keys] table to ~/.config/quarry/config.toml (run quarry --default-config to see a commented example). Each line names an action and gives it one key or a list of keys:

toml
[keys]
run_statement = ["ctrl+enter", "ctrl+e"]   # several keys
run_all = "f9"                              # one key
themes = "alt+t"
quit = []                                   # no key (Quit stays in the command palette)

A line replaces all of that action's default keys. Actions you don't list keep their defaults.

How to write a key ​

Modifiers, then the key, joined with +. Case doesn't matter.

WriteFor
ctrl, alt, shiftModifiers, e.g. ctrl+shift+enter
a … z, 0 … 9, ?, /, …A character
enter, esc, tab, space, backspace, delete, insertNamed keys
up, down, left, right, home, end, pageup, pagedownMovement keys
f1 … f24Function keys

When keys collide ​

quarry sorts collisions out for you, so a new binding never silently breaks another:

  • Your binding wins over a default. If you bind run_all = "ctrl+r", Ctrl+R stops opening History. When an action is left without any key this way, quarry tells you when the TUI starts, and you can give it a new one.
  • Two of your own bindings on one key: one action keeps it and you get a warning naming both. The action that comes first in the list below wins.
  • Alt+1…9 always jump to tabs and can't be rebound.
  • Keys the editor uses itself (Ctrl+C, X, V, A, Z, Y, D, /, Space) keep their editor meaning while the editor has focus. A binding on one of them works everywhere else, and quarry warns you about it.
  • A plain character such as ? works only when you aren't typing in a text field, so it never gets in the way of your SQL.
  • An unknown action or key is skipped with a warning; the rest of [keys] still applies.

Warnings appear as notices when the TUI starts.

Actions you can rebind ​

Global ​

ActionDefault keysDoes
commandsCtrl+PCommand palette
helpF1, ?Keyboard shortcuts
connectionsCtrl+OConnections
new_queryCtrl+TNew query tab (in the explorer: for the selected database)
close_tabCtrl+WClose tab
next_tabAlt+→, Ctrl+PgDnNext tab
prev_tabAlt+←, Ctrl+PgUpPrevious tab
next_paneF6Focus the next pane: explorer, editor, results
prev_paneShift+F6Focus the previous pane
focus_explorerAlt+0Focus the explorer
toggle_explorerCtrl+BShow or hide the explorer
go_to_tableCtrl+GGo to a table
themesCtrl+YTheme picker
historyCtrl+RQuery history
quitCtrl+QQuit

Query tabs ​

ActionDefault keysDoes
run_statementCtrl+Enter, Alt+Enter, Ctrl+ERun the statement under the cursor, or the selection
run_allF5, Ctrl+Shift+EnterRun everything in the editor
cancelEsc, Ctrl+CCancel the running query
explainF7Explain
explain_analyzeShift+F7Explain analyze
format_sqlAlt+FFormat the SQL
save_favoriteCtrl+SSave the query as a favourite
exportCtrl+XExport results to a file
editor_smallerCtrl+↑Make the editor smaller
editor_largerCtrl+↓Make the editor larger

Keys inside a pane, such as moving in the results grid or the explorer, are fixed. They're listed in Keyboard shortcuts.

Vim mode ​

Set vi = true under [main]. The REPL gets vi editing, and the TUI's SQL editor gets vim's modes:

  • Normal is where you start. The cursor is a block and the status bar says NORMAL.
  • Insert (i, a, o, …) is ordinary typing, with completion as you type. The cursor turns into a bar.
  • Visual (v) and visual-line (V) select text for an operator.

Esc goes back to normal mode. In normal mode, Esc moves to the results, as it does without vim. The app-wide keys (run, explain, tabs, palette) work in every mode.

KeysDo
h j k lLeft, down, up, right
w b eNext word, previous word, end of word
0 ^ $Line start, first non-blank, line end
gg GFirst line, last line (5G goes to line 5)
Ctrl+D / Ctrl+UHalf a page down / up
i a I AInsert before, after, at line start, at line end
o ONew line below / above
d c y > < + a motionDelete, change, yank, indent, dedent: dw, c$, y2j, >G
dd cc yy >> <<The same on whole lines
ciw, diw, yawChange, delete, yank a word (a includes the space after it)
x XDelete the character under / before the cursor
s SReplace the character / the line
D C YDelete / change to the end of the line, yank the line
r + a characterReplace the character under the cursor
JJoin the next line onto this one
p PPaste after / before. Whole lines go below / above.
u, Ctrl+RUndo, redo

A number in front repeats: 3j, 2dd, 5x. Yanks and deletes go to the system clipboard, so you can paste them elsewhere, and text copied elsewhere pastes with p.

Not supported: search (/), marks, macros, registers other than the clipboard, . to repeat, and : commands.

Released under the MIT licence.