Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 592
kamikaze_pilot Avatar asked Aug 26 '13 05:08

kamikaze_pilot


2 Answers

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.

like image 51
michas Avatar answered Nov 14 '22 09:11

michas


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

set -o vi
like image 1
cforbish Avatar answered Nov 14 '22 07:11

cforbish