3

Sometimes when I reverse-search cmd in a shell I don't find a correct match and just want to execute search query as it is.

Is there a way in bash/zsh and friends to execute it without discarding input?

1 Answer 1

2

In zsh, you can use the variables LASTSEARCH and LASTABORTEDSEARCH. They're only available inside editor widgets.

An editor widget is a function that has been made into an editor widget with zle -N and that is invoked via a key binding. (The key binding can be ESC-x — : in vi mode.)

For example, the following code binds ESC-s to replace the current command line with the last incremental search. If you press ESC-s during an incremental search, that's the search in progress (which gets aborted).

function set-buffer-last-search { LBUFFER=$LASTSEARCH; RBUFFER=; }
zle -N set-buffer-last-search
bindkey '\es' set-buffer-last-search
1
  • I was hoping that it's possible to do so without any customisation, but apparently not. Commented Aug 30, 2020 at 22:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.