In Bash (Mac/Linux terminal shell), can the up and down arrow keys be made to function as they do in text editors?

In text editors, if I press the up and down arrow keys, it moves the cursor between lines of text.

In Bash, if I’m typing a long command that spans multiple lines and I press the up and down arrow keys, it cycles through the command history.

I want the former behavior in Bash. Is this possible? If not, is there any way to move the cursor directly up or down in a multi-line command?


Solution 1:

No, it's not possible. Bash uses GNU Readline to handle interactive line input. There is no command in Readline that moves between display lines as you desire, nor is there a configuration variable comparable to the line-move-visual variable of GNU Emacs that causes next-line and previous-line to move by display lines.

Solution 2:

What I do is press CTRL + Left Arrow and it will leap to the first letter after the last space found. You can quickly get to where you need by doing this.

Solution 3:

Maybe you're looking for something like xiki. It's like a shell/text-editor.

Here's a video demo: http://youtu.be/bUR_eUVcABg

Solution 4:

You can use Ctrl+Left and Ctrl+Right to navigate through words rather than characters, and Home and End to go to the beginning and the end of the typed command.

Solution 5:

See also the bash(1) manpage under the heading Commands for Moving section for other navigation shortcuts.