2

Often, when I'm typing in a super long command(usually ruby on rails console code), I decide that I need to do something else first and therefore, have to delete the command which I just typed(but not executed) on the terminal. Is there a shortcut to do this? command+delete and option+delete do not work. The down arrow works sporadically.

If it helps, I'm on The El Capitan Developer Preview 3 but I've noticed this behaviour on Yosemite as well.

3 Answers 3

5

If you are using emacs keybindings (default for bash, zsh, pry (ruby interpreter), python and many more), ^u (control + u) might be what you want - it erases everything prior to your cursor. If you want to stop writing the command and forget what you did, use ^c (control + c), which is, by the way, a SIGKILL(9) signal (see man signal).

By the way, the keybindings not only work on OS X 10.11, but also on all Unix-like systems I've ever seen.

2

In addition to the other emacs shortcuts posted by theoden, you can also use ^a (control + a) to return to the beginning of the line to edit it, and ^k (control + k) to cut the line.

Hope that helps.

2
  • I'll be honest- I didn't know about these two either. But ^u (control + u) seems to be exactly what I want. Jul 21, 2015 at 20:40
  • 1
    I didn't know about ^u either, and I've been using bash for ages!
    – KIsmay
    Jul 21, 2015 at 21:20
1

Usually I want to keep the command I've been typing and just not run it. In that case, under Bash, at least, hitting esc-# will add a hash character to the beginning of the line and then (essentially) hit enter, shoving the command into your history. You can then run whatever commands you want, and use your shell history keys to bring back the previous command. Delete the hash at the beginning of the line, go to the end, and finish it up.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .