Reputation: 127
I'm searching for the couple of shortcuts to allow to write multilines commands in the terminal.
I know it exist, I used it many times, but I can't remberber them, and I don't find them in google...
The behavior it have:
Once in the middle of a line, it will "delete" the right part, and when we press the Enter button, it don't execute the command, but go to a new line (that start with '>' if I well remember).
When we are done, we press the second shortcut, and it paste the part that where deleted before, and the Enter key behavior come back as the original.
(I tought it was something like Ctrl+j / ctrl+f, but it's not, I also tried many combination but never succeed)
Hoping you remember them, you'll make my day. Thanks!
On a command like this (a call to a ros service, providing arguments):
rosservice call /operatorshift/updateProgramSteps "category: ''
name: ''
steps:
- command: ''
args: ''
othersarg ''"
The steps argument is an array, and I want to provide more than one step, without deleting and rewriting the next lines.
The behavior is as follow:
I move my cursor at the end of the 5th line (args: '' [HERE]), and I press the first shortcut. The command would look like:
rosservice call /operatorshift/updateProgramSteps "category: ''
name: ''
steps:
- command: ''
args: ''
and I press "enter", not to execute the command, but to add a new line (and the '>' character appear on the left of my cursor, instead of my computer's name). I can write my other "step", pressing "enter" many time if I want, so my terminal would look like this:
rosservice call /operatorshift/updateProgramSteps "category: ''
name: ''
steps:
- command: ''
args: ''
> - command: 'example'
> args: ''
>
Then I'm done editing this command, so I press the second shortcut, that retrieve what the first have deleted, and the "enter" key get its default behavior (execute the command)
rosservice call /operatorshift/updateProgramSteps "category: ''
name: ''
steps:
- command: ''
args: ''
> - command: 'example'
> args: ''
othersarg ''"
(not sure that '>' stay on screen after pressing the second shortcut)
I remember using it on Ubuntu 14.04, and on 16.04, with the default shell, without having to install a special package.
Upvotes: 0
Views: 6176
Reputation: 726
Sadly, I think the easiest solution is to use bash's edit-and-execute-command feature; from the manual:
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.
if you use bash in vi mode, you can invoke it by simply pressing v
in normal mode.
This will open your command in your editor set up by $VISUAL
or $EDITOR
environmental variables.
Upvotes: 1
Reputation: 26895
Could it be heredoc ?
$ cat << EOF
> \$ Working dir "$PWD" `pwd`
> EOF
$ Working dir "/home/user" /home/user
Upvotes: 0
Reputation: 446
Just type "\", and when you press enter the ">" symbol you mentioned will appear
Upvotes: 2