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.
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:
j
is removed from the buffer and the command fires@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:
j
is written to the bufferj
is removed from the buffer and the command firesYeah,
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, likeSet-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.
Most helpful comment
I see. Thanks for clarifying it.
I have changed the title and PR description to reflect what is really asked for.