Keybindings
There are two major editing modes available: Emacs mode and Vi mode. The mode
can be changed via the key_bindings property in the config file (~/.myclirc) or
toggled via the F4 key.
Emacs mode is the default. In Emacs mode you can type Control-a to go to the beginning of a line, Control-e to go to the end of a line, with many more options for navigation, similar to the defaults of the readline library.
When Vi mode is enabled you can use vi-style navigation, along with modal editing features offered by Vim in the REPL, including text objects.
Most key bindings are simply inherited from prompt-toolkit.
Mycli also adds some custom keybindings which are summarized here along with completion navigation.
The Basics: Custom Bindings and Completion Navigation
F1
F1 opens the web documentation index in a browser tab.
F2
F2 toggles smart completions.
F3
F3 toggles multi-line mode.
F4
F4 toggles Emacs/Vi editing modes.
Tab
Tab will summons completions + always advance in candidates (configurable).
Control-Space
Control-Space will summon completions or advance in candidates if present (configurable).
Enter
Enter will choose a completion candidate.
Escape
Escape will cancel the completions popup.
Control-g
Control-g will cancel the completions popup.
Control-r
Control-r will search the query history with fzf if available, or use
prompt-toolkit's
reverse-i-search as a fallback (configurable).
Alt-Enter
Alt-Enter will introduce a line break in multi-line mode, or dispatch the current query in single-line mode.
The keyboard combination Alt-Enter usually sends the sequence
ESC,Enter on the wire, and it may also be possible to use the ESC,Enter
key sequence.
Arrow keys
Arrow keys will perform Completion navigation (when popup is present).
Right-arrow
The right-arrow will accept the full-line history suggestion (when suggestion is visible).
Control-d
Control-d will exit the REPL (configurable).
In Emacs Mode Only
A comma indicates a sequence of multiple keystrokes.
Control-x, p
Control-x, p will prettify and indent the current statement, usually into multiple lines.
Only works for buffers containing single SQL statements.
Control-x, u
Control-x, u will unprettify and dedent the current statement, usually into one line.
Only works for buffers containing single SQL statements.
Control-o, d
Control-o, d will insert the current literal date at the cursor, as defined by NOW() on the
server.
Control-o, t
Control-o, t will insert the current literal datetime at the cursor, as defined by NOW() on
the server.
Control-o, Control-d
Control-o, Control-d will insert the quoted current literal date at the cursor, as defined by NOW()
on the server.
Control-o, Control-t
Control-o, Control-t will insert the quoted current literal datetime at the cursor, as defined by
NOW() on the server.
Control-o, u
Control-o, u will insert the current literal Unix timestamp at the cursor, in seconds, as defined
by time.time() on the client.
Control-o, Control-u
Control-o, Control-u will insert the current literal Unix timestamp at the cursor, in microseconds, as
defined by time.time() on the client.
Alt-r
Alt-r will search the query history with fzf even if ~/.myclirc
is configured not to use fuzzy search on the default key Control-r.
Advanced
Since Alt key combinations usually work by sending a series of characters on the wire, there is sometimes an ambiguity with regard to which characters were physically typed. A timeout heuristic is used to resolve this.
Advanced users, and those on slow connections, may want to consult the following
settings in ~/.myclirc to adjust the timeout heuristic. The threshold is separate
for Emacs and Vi edit modes:
[keys]
# How long to wait for an Escape key sequence in vi mode.
# 0.5 seconds is the prompt_toolkit default, but vi users may find that too long.
# Shorter values mean that "Escape" alone is recognized more quickly.
vi_ttimeoutlen = 0.1
# How long to wait for an Escape key sequence in Emacs mode.
emacs_ttimeoutlen = 0.5