955

It's a situation that has happened quite often to me: after I press (with a different intention) Ctrl-S in a terminal, the interaction (input or output) with it is frozen. It's probably a kind of "scroll lock" or whatever.

How do I unfreeze the terminal after this?

(This time, I have been working with apt-shell inside a bash inside urxvt--not sure which of them is responsible for the special handling of Ctrl-S: I was searching the history of commands backwards with C-r, as usual for readline, but then I wanted to go "back" forwards through the history with the usual--at least in Emacs--C-s (1, 2, 3), but that caused the terminal to freeze. Well, scrolling/paging to view past things still works in the terminal, but no interaction with the processes run there.)

9
  • 51
    I was working in vim and I pressed Ctrl-S to save my edits. Uh-oh XD
    – ADTC
    Commented Jul 22, 2016 at 14:47
  • 23
    Why does that exist in first place?
    – neverMind9
    Commented Dec 13, 2018 at 23:31
  • 2
    This sometimes happens to me: accidentally freezing Vim, in a xfce4-terminal (it's actually the terminal that is frozen). Various xon-xoff solutions (Ctrl-Q ...) had no effect. Although no keyboard shortcut was evident, I noticed that from the terminal menu that the terminal had become set to "Read-Only." Unchecking that restored terminal responsiveness. Commented Sep 29, 2020 at 21:33
  • 2
    Thank you @VictoriaStuart - this has been driving me insane. Now I just need to figure out the keystroke that causes the RO mode...
    – csknk
    Commented Jun 22, 2021 at 13:45
  • 1
    @Ryan that's to break SSH sesion. Commented Jul 20, 2021 at 17:16

3 Answers 3

1141

Press Ctrl-Q to unfreeze.

This stop/start scheme is software flow control, which is implemented by the OS's terminal device driver rather than the shell or terminal emulator. It can be configured with the stty command.

To disable it altogether, put stty -ixon in a shell startup script such as ~/.bashrc or ~/.zshrc. To instead just allow any key to get things flowing again, use stty ixany.

25
  • 11
    Thank you! BTW, there they suggested Ctrl-C; does it work, too? (And at another place, they suggested Ctrl-Q, just as you.) Commented Apr 27, 2011 at 12:41
  • 30
    Ctrl-C does work, but it also sends an interrupt signal, which one generally wouldn't want. (Btw, the keys being used for these things are all configurable through stty.)
    – ak2
    Commented Apr 27, 2011 at 13:10
  • 25
    THANK GOD !! This has been something bugging me for years. Not sure why VIM just hasn't implemented this as a native shortcut for save instead of whatever the hell it does. Good to know there is an escape from the prison which is the frozen VIM screen due to natural use of CTRL+S (save shortcut) that is applicable in nearly all applications EXCEPT VIM. Commented Mar 14, 2015 at 18:20
  • 15
    @SanuelJackson Ctrl-S "save shortcut" is applicable in nearly all DESKTOP application EXCEPT vim. And Except Emacs. And Nano. And every other "application" you can run on a terminal, exactly because it's already used by the terminal for flow control. It's the same reason you won't find a Linux Desktop application using the Ctrl-Alt-FN shortcuts: because they're already used by the system.
    – gerlos
    Commented Sep 23, 2015 at 15:45
  • 5
    @SamuelJackson there is nothing stopping you from binding ctrl-s to :w command in your .vimrc, see here for example: stackoverflow.com/a/11298171/2380702 Commented Sep 22, 2016 at 10:03
475

Ctrl-Q is indeed the answer. I thought I'd toss in a little history of this that is too long to fit in the margins of ak2's correct answer.

Back in the dark ages, a terminal was a large piece of equipment that connected to a remote device (originally another terminal because teletypes were so much easier to learn to operate than a telegraph key) over a long wire or via phone lines with modems. By the time Unix was developing, the ASCII code was already well established (although the competing EBCDIC code from IBM was still a force to be reckoned with).

The earliest terminals kept a printed record of every character received. As long as the characters arrived no faster than the print head could type them, at least. But as soon as CRT based terminals were possible, the problem arose that only about 25 lines fit on the CRT, and 25 lines of 80 characters represented enough RAM that no one thought seriously about providing more RAM for characters that had scrolled off the top of the screen.

So some convention was needed to signal that the sending end should pause to let the reader catch up.

The 7-bit ASCII code has 33 code points devoted to control characters (0 to 31 and 127). Some of those had really well established purposes, such as NUL (blank paper tape leader for threading, gaps, and splices), DEL ("crossed out" characters on paper tape indicated by punching all seven holes), BEL (ding!), CR, LF, and TAB. But four were defined explicitly for controlling the terminal device itself (DC1 to DC4 aka Ctrl+Q, Ctrl+R, Ctrl+S and Ctrl+T).

My best guess is that some engineer thought that (as mnemonics go), "S" for "Stop" and "Q" for "Continue" weren't too bad, and assigned DC3 to mean "please stop sending" and DC1 to mean "ok, continue sending now".

Even that convention was already well established by the time Unix was leaving nest at Bell Labs to go out into the world.

The convention is known as software flow control, and is extremely common in real serial devices. It is not easy to implement correctly, as it prevents the use of either of those characters for any other purpose in the communications channel, and the Stop signal has to be handled ahead of any pending received characters to avoid sending more than the receiving end can handle.

If practical, using additional signals out of band from the serial data stream for flow control is vastly preferred. On directly wired connections that can afford the additional signal wires, you will find hardware handshake in use, which frees up those characters for other uses.

Of course, today's terminal window is not using an actual physical serial port, has scroll bars, and doesn't really need software handshaking at all. But the convention persists.

I recall the claim that Richard Stallman received complaints about his mapping Ctrl+S to incremental-search in the first releases of emacs, and that he was rather unsympathetic to any user that had to depend on a 7-bit, software flow controlled connection.

18
  • 18
    Thanks very much for that bit of history. I recently disabled flow control by default in a terminal emulator I maintain, but had to reinstate it rather quickly after vocal protests from Unix traditionalists who do still use it. I set the ixany bit instead, so at least people who press ^S without knowing about ^Q don't get stuck.
    – ak2
    Commented Apr 27, 2011 at 22:45
  • 3
    @RBerteig I ran into something similar learning about backspace and delete. Backspace is officially ^H and delete is ^? Some people like the Emacs developers (Stallman again?) wanted ^H available for general purpose like shortcuts like Help. The escape sequence ^[[3~ or something like that was created to replace ^? and backspace now became the old delete character ^?. In fact, I've seen ncurses specifically patched on Linux distros to remap thoses keys in terminfo whereas ncurses on FreeBSD is unpatched causing some of the annoying confusion causing backspace to not work.
    – penguin359
    Commented Apr 28, 2011 at 10:48
  • 34
    I used to wonder why DEL had the code 127 rather than being grouped with the other control characters, until I first played with some paper tape and an ASR33. Once I realized that it had the effect of punching all the holes, which meant it could be overstruck on any previously punched character to delete it, it made sense.
    – RBerteig
    Commented Apr 28, 2011 at 19:08
  • 4
    @SanuelJackson It's been some time since I looked closely, but the default vimrc that ships with windows has mapped <C-s> to ":update" for many years. I'm also fairly certain I've seen it on some distros for gvim in the past as well. If you are using vim in a terminal, though, this history is still very much relevant. Modern terminal emulators still implement the flow control keys, so even if vim mapped them it would never see them unless each user went out of their way to disable flow control as described in the accepted answer.
    – Drew
    Commented Apr 22, 2016 at 22:30
  • 5
    @CMCDragonkai Nope. Nothing at all to do with SIGCONT and SIGSTOP. SIGTSTP is generated by the terminal driver when ^Z is typed, and can be ignored unlike SIGSTOP which cannot. No keystroke sends SIGCONT, it is the signal sent by whatever command in your shell you use to continue a stopped job. The ^S and ^Q keys act directly on the terminal driver stack, and don't generally send a signal.
    – RBerteig
    Commented Jan 24, 2017 at 20:09
17

Control Keys: perfrom special functions on Shell

  • Ctrl-S : Pause Display
  • Ctrl-Q : Restart Display
  • Ctrl-C : Cancel Operation
  • Ctrl-U : Cancel Line
  • Ctrl-D : Signal End of File
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .