zsh-users
 help / color / mirror / code / Atom feed
* A wrong bindkey command breaks the way bck-i-search (Ctrl+R) works
@ 2021-07-26 14:13 Peter Slížik
  2021-07-26 15:58 ` Mikael Magnusson
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Slížik @ 2021-07-26 14:13 UTC (permalink / raw)
  To: zsh

[-- Attachment #1: Type: text/plain, Size: 1627 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2159 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-07-27 22:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 14:13 A wrong bindkey command breaks the way bck-i-search (Ctrl+R) works Peter Slížik
2021-07-26 15:58 ` Mikael Magnusson
2021-07-26 21:10   ` Bart Schaefer
2021-07-27 10:31     ` Peter Slížik
2021-07-27 14:51       ` Bart Schaefer
2021-07-27 15:09         ` Peter Slížik
2021-07-27 15:42           ` Bart Schaefer
2021-07-27 15:44             ` Peter Slížik
2021-07-27 22:35         ` Mikael Magnusson
2021-07-27 22:38           ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).