Readline: Integrating Vim and Nano

If you’re comfortable editing text in your favorite editor and frustrated using Readline’s shortcuts, you’re not alone. The good news is that there’s something easier—and a little more powerful. By pairing Readline with an external editor, you can edit a command line using familiar key sequences.

Before we look at how Readline chooses which editor to launch, here’s a quick review of the key sequences you’ll use with Readline, Vim, and Nano.

[table id=1 /]

Here’s what happens behind the scenes. As you type a command on a Bash shell command line, Readline stores the text in an editable buffer.

When you press the Readline key sequence C‑x + C‑e in a Linux or Windows environment Readline writes the contents of the buffer to a temporary file and opens that file in your external editor. After you save the file and close the editor, Readline replaces the buffer with the contents of the saved file. If the file ends with a newline (most editors add this automatically) Bash immediately executes the edited command.

Note: Only the executed command is added to history; the original unedited version is discarded.