Issue
Suppose I have typed and executed a long BASH command on the command line. Now I want to split it up. So with the history I have my long command again, but now I cannot give Enter to insert a newline. How do you do that?
Solution
You can use two shortcuts to do that ctrl + k
and ctrl + y
:
echo "some command" && echo "some other long command"
Now move cursor somewhere (in my example, cursor is marked by >
):
echo "some command" && > echo "some other command"
Now press ctrl + k
- this will cut everything after a cursor:
echo "some command" && >
Now put \
(backslash) and press enter
:
echo "some command" && \
>
And now paste the part you've previously cut by ctrl + y
:
echo "some command" && \
echo "some other long command"
Edit: to move more easily around in a long command, you can use shortcuts:
alt + b
- move one word backwards (on Mac OS X:ESC + b
)alt + f
- move one word forwards (on Mac OS X:ESC + f
)
Ultra-solution
You can also open current line in a editor using Ctrl-x + Ctrl-e
(two shortcuts, one after another). Then edit it just as a regular text file, save & quit and voila, edited command will execute.
If you want to choose which editor to use, just set EDITOR
environment variable.
Answered By - kamituel