Skip to content

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 many projects that use prompt_toolkit (including radian), but these bindings are unavailable when vi mode is enabled (e.g. with set -o vi in bash, bindkey -v in zsh, or options(radian.editing_mode = "vi") in radian).

Not having access to emacs keybindings is a problem for the autosuggestions feature from merged PR #223.

As I described in #223, 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 using

options(radian.emacs_bindings_in_vi_insert_mode = False)

in .radian_profile.

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 radian, 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 radian with autosuggestions enabled, run:

pip install git+https://github.com/mskar/radian@emacs_bindings_in_vi_insert_mode

@randy3k
Copy link
Owner

randy3k commented Oct 11, 2020

Thank you for making it clean and easy to merge.

@randy3k
Copy link
Owner

randy3k commented Feb 5, 2021

@mskar

this is discovered that this PR introduced a little delay after a single escape is pressed. #252 (comment)
I think it may be reasonable to set the default value of the setting to False warning users of the side effects.

@mskar
Copy link
Author

mskar commented Feb 5, 2021

Yes, I agree that this feature should not be enabled by default.
The reason for the delay is that Escape is used for Alt bindings (for example, Alt F moves one word to the right). When Escape is pressed, there is a delay to see if another key (for example, F) will then be pressed. I don't think there is any way to avoid this. Setting the ttimeoutlen variable to be lower reduces the delay, but if we make ttimeoutlen too low, it will be difficult to use motions.
I will prepare a new pull request that will disable the feature by default and include a warning about the delay.

@randy3k
Copy link
Owner

randy3k commented Feb 5, 2021

Thank you. I have already changed the default value in the latest release.

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.

3 participants