[Chapter 9] 9.3 Reprinting Your Command Line with CTRL-r
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:34:54Z

#

| Chapter 9 Saving Time on the Command Line |

## 9.3 Reprinting Your Command Line with CTRL-r

You're logged in from home, running a program, and answering a prompt. As you're almost done, modem noise prints `xDxD@!` on your screen. Where were you? Or you're typing a long command line and a friend interrupts you with write (1.33) to say it's time for lunch. Do you have to press CTRL-u (9.2) and start typing over?

If your system understands the rprnt character (usually set to CTRL-r), you can ask for the command line to be reprinted as it was. In fact, you can use CTRL-r any time you want to know what the system thinks you've typed on the current line - not just when you're interrupted. But this only works in the normal cooked (41.2) input mode; programs like vi that do their own input processing may treat CTRL-r differently. Here's an example:

>     % egrep '(10394|29433|49401)' /work/symtower/

>     Message from alison@ruby on ttyp2 at 12:02 ...
>     how about lunch?
>     EOF[CTRL-r]
>     egrep '(10394|29433|49401)' /work/symtower/logs/*

After the interruption, I just pressed CTRL-r. It reprinted the stuff I'd started typing. I finished typing and pressed RETURN to run it.

If you use a shell like the Korn shell that has interactive command editing, you can probably use it to reprint the command line, too. In bash, for example, from vi editing mode, CTRL-r still seems to start an Emacs-style reverse search. So I added this fix to my ~/.inputrc file:

>     # By default, ^R seems to do a "reverse-i-search",
>     # even when not editing!  Workaround:
>     "\C-r": redraw-current-line

- JP

9.2 Fix a Line Faster with Line-Kill and Word-Erase |  | 9.4 Use Wildcards to Create Files?