On Tue, Jan 17, 2012 at 04:25, David Korn <[email protected]> wrote:
> 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=========================== > I made a bit enhancement: 1) The current cursor position may not be at the end of the inputted text, so I use ${.sh.edcol} other than -1; 2) I often copy and paste on the command line and there are possibilities that there is `jj' in the pasted text but in this case I want `jj' to be inserted into the command line instead of going to vi NORMAL mode. Following is the updated version: float g_EdSeconds=0 function _keybd_jj { if (( .sh.edcol == 0 )); then (( g_EdSeconds = SECONDS )) return fi if [[ ${.sh.edchar} == j && ${.sh.edmode} == $'\e' ]]; then if [[ ${.sh.edtext:.sh.edcol - 1:1} == j ]] \ && (( SECONDS - g_EdSeconds > .1 && SECONDS - g_EdSeconds < .5 )) then .sh.edchar=$'\b\e' else (( g_EdSeconds = SECONDS )) fi fi } trap _keybd_jj KEYBD > David Korn > [email protected] > _______________________________________________ > ast-users mailing list > [email protected] > https://mailman.research.att.com/mailman/listinfo/ast-users >
_______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
