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

vi mode: Introduce alternate escape sequence for insert mode #670

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

Conversation

benvansleen
Copy link

This PR introduces a new argument to the Vi::new constructor: the alternate_esc_seq. When set to (KeyCode::Null, KeyCode::Null), this does nothing.

alternate_esc_seq can be set to something like (KeyCode::Char('j'), KeyCode::Char('k')) -- allowing the user to press "jk" (without modifiers) to move from Vi insert mode to Vi normal mode.

I wrote this because I would love to be able to use "jj" to enter normal mode in Nu (like I do for all other similar vi-modes).

(I am very new to Rust, Nu, and Reedline; if something is non-idiomatic, please tell me!)

…rt mode (e.g. press "jk" to exit insert mode)
@benvansleen
Copy link
Author

Addressing: #499

Copy link

codecov bot commented Nov 18, 2023

Codecov Report

Merging #670 (dfa469b) into main (93af55c) will decrease coverage by 0.07%.
The diff coverage is 42.85%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #670      +/-   ##
==========================================
- Coverage   49.19%   49.12%   -0.07%     
==========================================
  Files          46       46              
  Lines        7930     7959      +29     
==========================================
+ Hits         3901     3910       +9     
- Misses       4029     4049      +20     
Files Coverage Δ
src/edit_mode/vi/mod.rs 61.90% <42.85%> (-4.20%) ⬇️

... and 3 files with indirect coverage changes

@kuchta
Copy link

kuchta commented Nov 18, 2023

Actually all other major vi modes (vim, bash, zsh) uses Meta (Alt) + whatever for entering normal mode. If you get used to it, it's indispensable, but reedline is the only one that doesn't support that...

@tamlok
Copy link

tamlok commented Dec 23, 2023

Can we use ctrl+[ to exit insert mode?

@benvansleen
Copy link
Author

@tamlok
Yes, the keycode C-[ is equivalent to ESC.

@fdncred
Copy link
Collaborator

fdncred commented Jan 11, 2024

Is this exposed so that one can define what they like in the nushell config.nu keybindings section?

@benvansleen
Copy link
Author

@fdncred

I believe the config.nu configuration is defined within the nushell crate. In reedline, this configuration is exposed by the Vi constructor.

If this PR is approved, I will write an accompanying nushell PR.

@fdncred
Copy link
Collaborator

fdncred commented Jan 11, 2024

I believe the config.nu configuration is defined within the nushell crate.

yes, of course. What I'm saying is will there be some way to define it in the keybinings section like this below but changed somehow to allow for other key combinations to be used for alternate_esc_seq instead of just j/k.

  {
    name: abbr
    modifier: control
    keycode: space
    mode: [emacs, vi_normal, vi_insert]
    event: [
    { send: menu name: alias_menu }
    { edit: insertchar, value: ' '}
    ]
  }

@benvansleen
Copy link
Author

Ah, I see what you mean. Currently, on the reedline side of things, the keys composing the sequence are configured by the (new) 3rd argument to Vi::new:

Vi::new(insert_mode_keybinds, normal_mode_keybinds, (KeyCode::x, KeyCode::y))

This means the user can press "x" then "y" to exit insert-mode. (Passing (KeyCode::Null, KeyCode::Null) instead recovers the current behavior where only ESC exits insert-mode.)

I was thinking of implementing the nushell PR such that config.nu would look something like this:

...
bracketed_paste: true # enable bracketed paste, currently useless on windows
edit_mode: vi # emacs, vi
vi_alternate_esc_seq: { first: x, second: y }
shell_integration: true # enables terminal shell integration. Off by default, as some terminals have issues with this.
...

Achieving this with the existing keybindings section would require implementing something akin to emacs key-chords (since you press one key, release, then press the next). That would be a much, much wider-reaching change.

@eggcaker
Copy link

eggcaker commented Sep 6, 2024

any news?

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.

5 participants