Enable emacs keybindings in vi insert mode (ebivim) #392
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale:
Emacs keybindings are the default in many UNIX shells (e.g.
bash
uses GNUreadline
) and Python consoles (including ptpython), but these bindings are unavailable when vi mode is enabled (e.g. withset -o vi
inbash
,bindkey -v
inzsh
, orrepl.vi_mode = True
in ptpython).Not having access to emacs keybindings is a problem for the autosuggestions feature (
repl.enable_auto_suggest = True
), because the emacs bindingsCtrl-E
,Ctrl-F
, andAlt-F
are used to accept autosuggestions.Without these bindings, vi editing mode users will have to use the right arrow key to accept autosuggestions.
If there is one that vi users hate... it's using arrow keys.😁
There is a
Condition
calledebivim
to turn this feature on and off. Currently,ebivim
is set toTrue
by default to facilitate testing of this feature, but it can be disabled by addingrepl.emacs_bindings_in_vi_insert_mode = False
toconfig.py
.Some users may want to disable this feature, because it conflicts with one (rather useless) vim insert mode binding:
Ctrl-K
(insert digraph). If anyone needs to use digraphs in ptpython, they can enter vim by pressingCtrl-X
,Ctrl-E
(assumingvim
is their$EDITOR
) and then pressCtrl-K
followed by the digraph combo (e.g.n
,~
is ñ).Details
This pull request implements the bindings used for accepting autosuggestions, but also many others:
Please click here for the full list of keyboard shortcuts
Alt-B
: move left one wordAlt-C
: capitalize wordAlt-D
: cut right one wordAlt-F
: move right one wordAlt-H
: cut left one wordAlt-L
: lowercase wordAlt-U
: uppercase wordAlt-Y
: rotate killringAlt-.
: insert last argumentCtrl-A
: move to line startCtrl-B
: move left one characterCtrl-D
: cut right one characterCtrl-E
: move to line endCtrl-F
: move right one characterCtrl-H
: cut left one characterCtrl-K
: cut to line endCtrl-U
: cut to line startCtrl-W
: cut left one wordCtrl-Y
: pasteCtrl-_
: undo (in addition to_
,-
works too)Ctrl-X
,Ctrl-E
: edit in$EDITOR
and execute (also works ifCtrl
is released afterCtrl-X
)To install a version of ptpython with autosuggestions enabled, run:
pip install git+https://github.com/mskar/ptpython@emacs_bindings_in_vi_insert_mode