kamikaze_pilot
kamikaze_pilot

Reputation: 14834

text editor mode for calling bash command

suppose I want to enter a multiline command via bash I know that I can append \ in the end of the line to enter a new line

however is it possible to enter a legitimate "text editor mode" where you don't even have to enter \ and simply press enter would suffice

eg..you type in the command into the command line then before entering the parameters you press some magic button which allows you to enter a vi like mode then you enter stuff into the "vi mode" then you exit and then the text you entered in the "vi mode" turns into the parameters of the command then you press enter then the command executes

is it possible to do that in bash command line? if so, how do I do it?

Upvotes: 5

Views: 2270

Answers (3)

beroe
beroe

Reputation: 12316

You can edit the previous command in vi or your default editor by using the fc command. This pops open an editor window and when you exit it executes the edited command. That mode could bed used repeatedly to edit a complex command.

Upvotes: 2

michas
michas

Reputation: 26495

See man bash:

   edit-and-execute-command (C-xC-e)
          Invoke  an  editor  on the current command line, and execute the
          result as shell commands.   Bash  attempts  to  invoke  $VISUAL,
          $EDITOR, and emacs as the editor, in that order.

Per default bash is configured for emacs mode, hence the emacs like C-xC-e command.

If you really like vi you can also set your bash into vi mode: set -o vi. This allows you to do normal line editing the vi way without invoking an explicit editor.

Upvotes: 6

cforbish
cforbish

Reputation: 8809

Bash can emulate vim mode (though not very well) with:

set -o vi

Upvotes: 1

Related Questions