Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable emacs keybindings in vi insert mode (ebivim) #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mskar
Copy link

@mskar mskar commented Oct 7, 2020

Rationale:

Emacs keybindings are the default in many UNIX shells (e.g. bash uses GNU readline) and Python consoles (including ptpython), but these bindings are unavailable when vi mode is enabled (e.g. with set -o vi in bash, bindkey -v in zsh, or repl.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 bindings Ctrl-E, Ctrl-F, and Alt-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 called ebivim to turn this feature on and off. Currently, ebivim is set to True by default to facilitate testing of this feature, but it can be disabled by adding repl.emacs_bindings_in_vi_insert_mode = False to config.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 pressing Ctrl-X, Ctrl-E (assuming vim is their $EDITOR) and then press Ctrl-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 word

  • Alt-C: capitalize word

  • Alt-D: cut right one word

  • Alt-F: move right one word

  • Alt-H: cut left one word

  • Alt-L: lowercase word

  • Alt-U: uppercase word

  • Alt-Y: rotate killring

  • Alt-.: insert last argument

  • Ctrl-A: move to line start

  • Ctrl-B: move left one character

  • Ctrl-D: cut right one character

  • Ctrl-E: move to line end

  • Ctrl-F: move right one character

  • Ctrl-H: cut left one character

  • Ctrl-K: cut to line end

  • Ctrl-U: cut to line start

  • Ctrl-W: cut left one word

  • Ctrl-Y: paste

  • Ctrl-_: undo (in addition to _, - works too)

  • Ctrl-X, Ctrl-E: edit in $EDITOR and execute (also works if Ctrl is released after Ctrl-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

@mskar mskar force-pushed the emacs_bindings_in_vi_insert_mode branch from 4ec1a1e to f46b641 Compare October 7, 2020 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants