7

Using Ctrl-R, I can search the history in bash.

But what to do, If I want to highlight the relevant word which has been typed upon by me.

Example:

(reverse-i-search)`mount': sudo mount /dev/sda2 /mnt

In the above reverse search, I want to highlight the world mount from the entire command sudo mount /dev/sda2 /mnt. How to achieve this in bash ?

5

readline (which bash uses for its line editor) doesn't have that possibility.

zsh does it by default though. By default, it highlights the searched text with underlining, but you can change that. For instance with:

zle_highlight=(isearch:standout)

Or:

zle_highlight=(isearch:fg=red)

(zle is zsh's line editor, like readline is bash's).

  • For me, in zsh, does not seem to highlight anything for me. How do I check whether zle is really the editor I am using for this? – Bernhard May 22 '14 at 6:05
  • @Bernhard, possibly you have an old version of zsh. highlighting was added relatively recently circa 2008 (4.3.6 or 7) – Stéphane Chazelas May 22 '14 at 13:51
  • Ah, that's clear. We are workin with the newest SLES here. zsh version is 4.3.6, so apparently added in 4.3.7. Thanks :) – Bernhard May 22 '14 at 14:02
  • With the release of bash 4.4, does this change: lists.gnu.org/archive/html/bug-bash/2016-09/msg00018.html ? See the feature mentioned in section 2 c for readline. – Sibi Sep 20 '16 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.