* David Korn <[email protected]> [2012-01-16 21:25]: > cc: [email protected] > Subject: Re: Re: [ast-users] Ksh93 quivalence of Vim mapping `inoremap jj > <ESC>'? > -------- > > > vim uses a timeout for such mappings so that you can still type > > in two consecutive "j" if you type slowly. While the KEYBD trap > > can be used for processing arbitrary long key combinations, it is > > not possible to implement a timeout which means you'd loose the > > ability to type in a regular "j". > > > > You can implement a timeout. The script below has a half second timeout. > In English the script say that if you typed a j in insert mode then > if the previous character was j and was type in less that a half second > ago, then backspace of the previous j and enter an escape. Otherwise > record the time that the j was typed. > ====================cut here=========================== > float ed_s=0 > function jj > { > if [[ ${.sh.edchar} == j && ${.sh.edmode} == $'\e' ]] > then if [[ ${.sh.edtext: -1:1} == j ]] && (((SECONDS-ed_s)<.5)) > then .sh.edchar=$'\b\e' > else ((ed_s=SECONDS)) > fi > fi > } > trap jj KEYBD > ====================cut here===========================
That is a pretty nice hack which solves the original poster's problem. However, it seems limited to key combinations which result in printable characters without special meaning to the shell editor that can be removed from .sh.edtext via backspace. So it is e.g. not possible to bind "^Uj" in emacs mode to an action with this method because the "^U" has side effects on .sh.edtext. This is actually relevant when one tries to handle character sequences emitted by terminal emulators like xterm for certain keys or key combinations like Home, End, Ctrl+Left etc. Handling such arbitrary character sequences would necessitate the use of a temporary buffer which can hold an incomplete, ambiguous character sequence without side effects. E.g. in order to bind the sequence "^Uj" to a certain action the "^U" would need to be stored in the temporary buffer until the next key is pressed and it becomes unambiguous whether the action associated to "^Uj" can should be executed or the "^U" can be passed to .sh.edchar. Basically this is the approach I've been using for a while to bind arbitrary character sequences to actions (see the attached script). What's missing here is the ability to have a timeout after which the contents of the temporary buffer are appended to .sh.edtext mostly because .sh.edtext is only accessible from within a KEYBD trap. More generally it would be nice if there was an easier way in ksh to edit keybindings. -- Guido Berhoerster
ksh-keybind.sh
Description: application/shellscript
_______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
