[Feature] Allow to configure additional vi mode Escape mapping
See original GitHub issueDescription
GNU read line allows to globally map jj
key sequence to ESC
for quick insert mode -> command mode transition.
I’m not aware of any global configuration for prompt_toolkit
.
Your environment
> pgcli --version
Version: 1.7.0
> uname -a
Linux myuser 4.11.9-1-ARCH #1 SMP PREEMPT Wed Jul 5 18:23:08 CEST 2017 x86_64 GNU/Linux
Currently I’ve patched the key_bindings.py
like so:
diff --git a/pgcli/key_bindings.py b/pgcli/key_bindings.py
index 646e6f7..b623c62 100644
--- a/pgcli/key_bindings.py
+++ b/pgcli/key_bindings.py
@@ -2,7 +2,8 @@ import logging
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.manager import KeyBindingManager
-from prompt_toolkit.filters import Condition
+from prompt_toolkit.key_binding.input_processor import KeyPress
+from prompt_toolkit.filters import Condition, ViInsertMode
from .filters import HasSelectedCompletion
_logger = logging.getLogger(__name__)
@@ -22,6 +23,14 @@ def pgcli_bindings(get_vi_mode_enabled, set_vi_mode_enabled):
enable_search=True,
enable_abort_and_exit_bindings=True)
+ @key_binding_manager.registry.add_binding('j', 'j', filter=ViInsertMode())
+ def _(event):
+ """
+ Typing 'jj' in Insert mode, should go back to navigation mode.
+ """
+ _logger.debug('Detected jj keys.')
+ event.cli.input_processor.feed(KeyPress(Keys.Escape))
+
@key_binding_manager.registry.add_binding(Keys.F2)
def _(event):
"""
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Add builtin settings to enable jj and jk map to escape #718
Some developers like to map jj , jk , or some other two key combination, to <Esc> in Vim. This is not so...
Read more >In bash vi mode, map jk to exit insert mode
As an addendum this is controlled by :set timeoutlen=<miliseconds> in Vim (see :h timeoutlen ). Several shell's or X11 has no such timeout ......
Read more >Avoid the escape key | Vim Tips Wiki - Fandom
Mappings. It can be convenient to use a mapping so that pressing a key, or sequence of keys, generates Escape. The :imap command...
Read more >VI Mode - Kate
Kate's VI mode is a project to bring Vim-like, modal editing to the Kate text editor and by extension to other KDE programs...
Read more >Basic VI Editor Commands - Marquette University
When entering a file, vi is in command mode. To enter text, you must enter insert mode. If in insert mode, enter command...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jonathanslenders
For my part that would be optimal, and I think it’s pretty likely that anyone going to the trouble to configure a
vi_insert_mode
key combination for one application is going to want it for every application using prompt_toolkit, just like the way it works with readline.You’ll need to edit key_binding.py
After modifying the above examples (btw thanks everyone for sharing those snippets), the following worked for me: The changes appear to be necessary due to updates to the prompt-toolkit library.