1

I have a Vim configuration that is somewhat unconventional. I bind Shift+H and Shift+L to move left by 7 characters and move right by 7 characters, respectively. This makes it easier for my brain to time the keyboard repeat to rapidly position the cursor where I want it to go as quickly as practically possible.

Anyway, I'm curious whether mapping a single key to such an action (move seven characters) like this is even possible, and I'd likely need to patch the shell itself. But, maybe the key binding system could allow for it?

I don't believe doing conversion or mapping at any other level (such as the terminal emulator) makes sense, as I need the terminal itself to keep sending the usual H and L characters.

  • For bash, the readline documentation (here and here) is frustratingly bare about its implementation of vi commands. But I don't believe they have implemented maps, so you're out of luck. – glenn jackman Jul 17 '17 at 20:59
2

CURSOR according to the zshzle(1) docs indicates that that can be moved about in ZSH:

rm ~/.zcompdump
bindkey -v
autoload -U compinit
compinit
function leftsevent {
    CURSOR=$(( CURSOR - 7 ))
}
function rightsaidfred {
    CURSOR=$(( CURSOR + 7 ))
}
zle -N leftsevent
zle -N rightsaidfred
bindkey H leftsevent
bindkey L rightsaidfred

(There does not appear to be any need on a single line of input to use bounds checking for < 0 or > $#BUFFER but that might be a good thing to do...)

  • this is amaaaziiing – Steven Lu Jul 17 '17 at 21:35
  • Is there an important reason why you remove ~/.zcompdump? Hm, it does seem like there is a lot I don't understand yet about compinit, etc. – Steven Lu Jul 17 '17 at 21:39
  • That line may help when you're fiddling around with new completions, and is not-so-much for day-to-day operations. – thrig Jul 17 '17 at 21:51
  • @StevenLu Zle is superior to bash's use of readline in many ways, but here you can do something similar with bind -x and READLINE_POINT. Searching for READLINE_POINT on this site should turn up some examples. – Gilles Jul 19 '17 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.