Last Updated: February 25, 2016
·
637
· unsignedzero

Fixing typos in the command line

Made a typo with a long command? No worries. There's a few ways to fix it.

  • Using fc. Hit enter (with the bad command) and hit ^c(Ctrl+c). The command will probably run for less than a second. Now type in fc and hit enter. This will load $EDITOR, or vi if not set from my experience, allowing you to edit the command as needed. You may give it multiple commands (one per line) and all will execute.
  • Alt+F/B. Under emacs mode, this will move forward/backwards one word. This isn't as efficent as fc, for large fixes but can be useful for small typos.
  • ESC. Under vi mode, one can just escape and b/e to the word, like emacs and edit as needed. This is mostly the same with fc, with $EDITOR set to vi. The only difference is that we have only one line.