Psreadline: Allow a key sequence binding like `j,k` to not prevent user from insert `j`

Created on 26 Jul 2020  路  6Comments  路  Source: PowerShell/PSReadLine

Description of the new feature/enhancement

You can bind a key sequence like j,k to a function or script block by Set-PSReadLineKeyHandler -Key 'j,k' -ViMode Insert -Function ViCommandMode, but a user cannot insert a character j after that.

Proposed technical implementation details (optional)

Quoted from https://github.com/PowerShell/PSReadLine/issues/1701#issuecomment-664020465

In vim, jk or jj to exit insert mode is super common. Usually it works like this:

  1. You press j
  2. j is written to the buffer
  3. A timer starts
  4. If you press the next key in the sequence before the timer is up, the j is removed from the buffer and the command fires
  5. If the key you press next isn't in the sequence, or the timer is up then it's treated like a literal
Issue-Enhancement Not-Planned

Most helpful comment

I see. Thanks for clarifying it.
I have changed the title and PR description to reflect what is really asked for.

All 6 comments

@dhatch48 You can do that by Set-PSReadLineKeyHandler -Key 'j,k' -ViMode Insert -Function ViCommandMode

@daxian-dbw I can't get that to work right. I mean it works, but you can't type j anymore.

Yeah, j will be bound after that and won't be treated as a literal character. I think that's just an example. Key sequences should be chosen to not interfere with the regular input, like Set-PSReadlineKeyHandler -Chord 'Ctrl+d,Ctrl+c' -Function CaptureScreen

Yeah, j will be bound after that and won't be treated as a literal character. I think that's just an example.

Nah jk or jj (what I use) to exit insert mode is super common. Usually it works like this:

  1. You press j
  2. j is written to the buffer
  3. A timer starts
  4. If you press the next key in the sequence before the timer is up, the j is removed from the buffer and the command fires
  5. If the key you press next isn't in the sequence, or the timer is up then it's treated like a literal

Yeah, j will be bound after that and won't be treated as a literal character. I think that's just an example. Key sequences should be chosen to not interfere with the regular input, like Set-PSReadlineKeyHandler -Chord 'Ctrl+d,Ctrl+c' -Function CaptureScreen

I think @SeeminglyScience explained it nicely. Many vim users have bindings of jj or jk to exit insert mode because it is so common to switch modes and this way it keeps your fingers on the home row vs. reaching for Esc key every time.

Anyway, I suppose a sequence timer/timeout is needed to make this work.

I see. Thanks for clarifying it.
I have changed the title and PR description to reflect what is really asked for.

Was this page helpful?
0 / 5 - 0 ratings