1

Recently I ran across a few articles with tips on how to more efficiently use bash that mentioned a combination I'd never tried: Ctrl-S (in the prompt, with no command running) to search the other way from Ctrl-R. Since I use Ctrl-R a lot, this was interesting.

However, I can't get it to activate on any bash installation I have access to (Mac OS Catalina, Git for Windows, Debian 10 over ssh, NixOS over ssh). Since most of them have various customizations that might interfere, I also tried --noprofile --norc, to no avail.

In each case, I of course first select a suitable line in history so that there's a "forward" to search, then try the key chord, but nothing happens. (Not only is there no prompt, typing any characters just puts them into the line without searching.) Likewise with Ctrl-R first to find something.

The documentation makes it sound like it works out of the box. So what's up?

4
  • Ctrl-S is also used for something else: unix.stackexchange.com/q/137842/70524 Try rebinding to something different (e.g. in my copy-pasta bashrcs and zshrcs I used set it to Ctrl-F)
    – muru
    Apr 14 at 1:54
  • @muru: Well, yes, but it never stops input, and I don't have stty set up to unpause without Ctrl-Q, either, so it ought to be quite obvious if it was suspending. (Also, a built-in feature of bash should not be interfered with by core tty features.) Apr 14 at 1:59
  • It's easy enough to test, though, isn't it?
    – muru
    Apr 14 at 2:01
  • @muru: Sure enough, looks like that's the problem, which is frankly the single most ridiculous thing I've heard all year. bash never executes outside a tty, and it comes with a default keybinding that all ttys prevent from running, and have for the last 60 years? Nonsensical. If you want to write up an answer (especially if you can explain how this came to be!), I'll accept it, but any self-answer I attempt at the moment would be too colored by disgust. Apr 14 at 2:15

1 Answer 1

3

The default shortcut CtrlS conflicts with the one for the XOFF control flow command. This can be tested by, e.g., disabling the XOFF command, or using another keybinding for the readline command:

stty -ixon  # or,
bind '"\C-f": forward-search-history'

I can't say for sure why this shortcut was used. It's been the default at least since bash 1.11 releases 30 years ago. But if I were to guess, I'd say that since these are the emacs keybindings, and emacs, an application that generally takes full control of the terminal, probably has no problems using CtrlS as a shortcut, so whoever added it to bash possibly just used that as the default without thinking too much. And apparently readline is supposed to turn off XON/XOFF for BSDs since 1.03, so presumably they just didn't notice that it didn't work by default on other systems.

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.