Key bindings and vim mode
The TUI's keys work out of the box, and you can change them: the app-wide ones and the ones each pane uses for itself. 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:
[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.
| Write | For |
|---|---|
ctrl, alt, shift | Modifiers, e.g. ctrl+shift+enter |
a … z, 0 … 9, ?, /, … | A character |
enter, esc, tab, space, backspace, delete, insert | Named keys |
up, down, left, right, home, end, pageup, pagedown | Movement keys |
f1 … f24 | Function 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 (its actions under Editor, such as Ctrl+C or Ctrl+Y) keep their editor meaning while the editor has focus. An app-wide binding on one of them works everywhere else, and quarry warns you about it. Give the editor action another key and the app-wide one works in the editor too.
- A pane's keys are its own.
grid_copy = "c"changes c in the grid only; the explorer's c is untouched. Within one pane a key runs one action, and a table view counts as a grid. A key held by a Global action never reaches a pane, and quarry says so. - A character can't be an editor shortcut, since you type it there. Editor actions need Ctrl, Alt or a function key.
- 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
| Action | Default keys | Does |
|---|---|---|
commands | Ctrl+P | Command palette |
help | F1, ? | Keyboard shortcuts |
connections | Ctrl+O | Connections |
new_query | Ctrl+T | New query tab (in the explorer: for the selected database) |
close_tab | Ctrl+W | Close tab |
next_tab | Alt+→, Ctrl+PgDn | Next tab |
prev_tab | Alt+←, Ctrl+PgUp | Previous tab |
next_pane | F6 | Focus the next pane: explorer, editor, results |
prev_pane | Shift+F6 | Focus the previous pane |
focus_explorer | Alt+0 | Focus the explorer |
toggle_explorer | Ctrl+B | Show or hide the explorer |
go_to_table | Ctrl+G | Go to a table |
themes | Ctrl+Y | Theme picker |
history | Ctrl+R | Query history |
quit | Ctrl+Q | Quit |
Query tabs
| Action | Default keys | Does |
|---|---|---|
run_statement | Ctrl+Enter, Alt+Enter, Ctrl+E | Run the statement under the cursor, or the selection |
run_all | F5, Ctrl+Shift+Enter | Run everything in the editor |
cancel | Esc, Ctrl+C | Cancel the running query |
explain | F7 | Explain |
explain_analyze | Shift+F7 | Explain analyze |
format_sql | Alt+F | Format the SQL |
save_favorite | Ctrl+S | Save the query as a favourite |
export | Ctrl+X | Export results to a file |
editor_smaller | Ctrl+↑ | Make the editor smaller |
editor_larger | Ctrl+↓ | Make the editor larger |
Editor
These apply while you type, and in vim's insert mode. vim's normal and visual modes keep their own keys.
| Action | Default keys | Does |
|---|---|---|
editor_complete | Ctrl+Space | Completion (it also opens as you type) |
editor_select_all | Ctrl+A | Select all |
editor_copy | Ctrl+C | Copy the selection |
editor_cut | Ctrl+X | Cut the selection |
editor_paste | Ctrl+V | Paste |
editor_undo | Ctrl+Z | Undo |
editor_redo | Ctrl+Y, Ctrl+Shift+Z | Redo |
editor_duplicate | Ctrl+D | Duplicate the line or selection |
editor_comment | Ctrl+/, Ctrl+7 | Comment or uncomment |
editor_line_up | Alt+↑ | Move the line up |
editor_line_down | Alt+↓ | Move the line down |
editor_delete_word_left | Ctrl+Backspace, Ctrl+H | Delete the word before the cursor |
editor_delete_word_right | Ctrl+Delete | Delete the word after the cursor |
Results and grids
The results of a query, and the grid of a table view.
| Action | Default keys | Does |
|---|---|---|
grid_up | k, ↑ | Up |
grid_down | j, ↓ | Down |
grid_left | h, ← | Left |
grid_right | l, → | Right |
grid_page_up | PgUp | Page up |
grid_page_down | PgDn | Page down |
grid_half_page_up | Ctrl+U | Half a page up |
grid_half_page_down | Ctrl+D | Half a page down |
grid_first_row | g | First row |
grid_last_row | G | Last row |
grid_first_column | 0, Home | First column |
grid_last_column | $, End | Last column |
grid_columns_right | w | A screen of columns right |
grid_columns_left | b | A screen of columns left |
grid_next_cell | Tab | Next cell |
grid_prev_cell | Shift+Tab | Previous cell |
grid_select | v | Select a block of cells |
grid_select_rows | V | Select whole rows |
grid_view_cell | Enter | View the cell and its row |
grid_copy | y | Copy cells as TSV |
grid_copy_rows | Y | Copy rows with a header |
grid_search | / | Search in the results |
grid_search_next | n | Next match |
grid_search_prev | N | Previous match |
grid_narrow_column | < | Narrow the column |
grid_widen_column | > | Widen the column |
grid_fit_column | = | Fit the column to its content |
grid_prev_result | [ | Previous result set |
grid_next_result | ] | Next result set |
grid_messages | m | Messages |
grid_to_editor | i | Back to the editor |
Table view
On top of the grid's keys.
| Action | Default keys | Does |
|---|---|---|
table_filter | f | Filter with a WHERE condition |
table_filter_by_value | F | Filter by the current cell's value |
table_sort | s | Sort by the column |
table_edit_cell | e, F2 | Edit the cell |
table_add_row | o | Add a row |
table_delete_rows | D, Delete | Mark rows for deletion |
table_apply | Ctrl+S | Review and apply staged changes |
table_discard | u | Discard staged changes |
table_reload | r, F5 | Reload |
Explorer
After the explorer_script key, the next key (s i u d c x n) picks the statement and is fixed.
| Action | Default keys | Does |
|---|---|---|
explorer_up | k, ↑ | Up |
explorer_down | j, ↓ | Down |
explorer_expand | l, → | Expand |
explorer_collapse | h, ← | Collapse, or go to the parent |
explorer_toggle | Space | Expand or collapse |
explorer_last | G, End | Last row |
explorer_open | Enter | Open a table, show a function, insert a column, switch database |
explorer_console | c | New query tab for this database or schema |
explorer_structure | s | Table structure |
explorer_insert_name | i | Insert the name into the editor |
explorer_script | g | Write a statement for the table, with s i u d c x n next |
explorer_filter | / | Filter the tree |
explorer_reload | r, F5 | Reload the schema |
explorer_new_connection | n | New connection |
explorer_disconnect | Ctrl+X | Disconnect |
Other tabs
| Action | Default keys | Does |
|---|---|---|
structure_next_section | Tab, ] | Structure tab: next section |
structure_prev_section | Shift+Tab, [ | Structure tab: previous section |
activity_pause | p, Space | Activity tab: pause or resume refreshing |
activity_refresh | r | Activity tab: refresh now |
activity_kill | K | Activity tab: kill the selected session |
text_copy | y | A definition or a table's DDL: copy the text |
text_to_editor | e | A definition or a table's DDL: open it in a query tab |
A few keys stay fixed: arrows and the other typing keys in the editor, Shift+arrows to select in a grid, scrolling in text and plan views, Esc, vim's keys, and the keys of dialogs. The grid actions apply to query results and table views. They're listed in Keyboard shortcuts. The hints in the status bar, in notices and in the empty editor follow your bindings.
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.
| Keys | Do |
|---|---|
| h j k l | Left, down, up, right |
| w b e | Next word, previous word, end of word |
| 0 ^ $ | Line start, first non-blank, line end |
| gg G | First line, last line (5G goes to line 5) |
| Ctrl+D / Ctrl+U | Half a page down / up |
| / or ? + text, Enter | Search forward or backward for the text (Esc cancels) |
| n N | The next match in the search's direction / the other way, wrapping round the text |
| . | Repeat the last change: dw, ciw with what you typed, 3dd, p, … |
| i a I A | Insert before, after, at line start, at line end |
| o O | New line below / above |
| d c y > < + a motion | Delete, change, yank, indent, dedent: dw, c$, y2j, >G |
| dd cc yy >> << | The same on whole lines |
ciw, diw, yaw | Change, delete, yank a word (a includes the space after it) |
| x X | Delete the character under / before the cursor |
| s S | Replace the character / the line |
| D C Y | Delete / change to the end of the line, yank the line |
| r + a character | Replace the character under the cursor |
| J | Join the next line onto this one |
| p P | Paste after / before. Whole lines go below / above. |
| u, Ctrl+R | Undo, 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.
A search is for the text as typed, not a pattern. All in lowercase it matches any case; with a capital letter in it, the case must match too.
Not supported: search as a motion (d/x), marks, macros, registers other than the clipboard, and : commands. A SQL editor's commands are a key away already (run, format, explain, save), so quarry leaves those to vim itself.
Related
- Keyboard shortcuts: every key, including the fixed ones
- Using the TUI
- Configuration file