Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

A wrong bindkey command breaks the way bck-i-search (Ctrl+R) works



Hello,

I created a few useful helper functions and bound them to specified keys.
For example, pressing " inserts a pair of quotes and puts the cursor inside them, like this: "|".
Another example, pressing a space fixes some of the typos I'm inclined to do repeatedly, e.g. pyhton<Space> is expanded to python<Space>.

The implementation is quite straightforward, the widget examines LBUFFER and RBUFFER and modifies LBUFFER accordingly.

_expand_abbreviations ()
{
    if [[ LBUFFER =~ 'this' && RBUFFER == 'that' ]]; then
        LBUFER+='something '    # mind the trailing space
    fi
}

zle -N expand-abbreviations _expand_abbreviations
bindkey ' ' expand-abbreviations

The problem with this solution is that it breaks the way that Ctrl+R history search works.
Before, typing a space inside Ctrl+R just underlined the space in the offered string:

% abcd efgh
zsh: command not found: abcd
% <Ctrl+R>abcd efgh    # the space is underlined here
bck-i-search: abcd<Space>

After using the " bindkey ' ' expand-abbreviations" command, the space finishes the Ctrl+R editor and inserts itself in front of the offered text:
% _abcd efgh    # a space prepended before abcd
and I'm not able to continue with the bck-i-search widget any more.

The behavior is identical for other bound keys, e.g. the double quote mark in the first example with quote duplication.

I'm pretty sure there's something I'm missing in the bindkey command, but frankly, the documentation is quite complex and I'm not sure what to look for.

Any suggestions are appreciated.

Best regards,
Peter Slížik


Messages sorted by: Reverse Date, Date, Thread, Author