I'm almost embarrassed to be admitting that I was Googling this today, but for some reason I am always forgetting the shortcut key to delete your current line in terminal. As a node.js enthusiast, vim user, and avid terminal user I often find myself hitting the up and down keys to cycle through my previous commands, but then I realize that I just want an empty line in the prompt so I can just type something. I hate sitting there mashing the backspace key and always thought to myself, "there must be a better way". This is that better way!
The first method for cleaning the text in your command shell is to do a combination of Ctrl A and Ctrl K. First, hold the control key and press the "a" key. This should bring the cursor to the beginning of your input text. Then hold the control key again and now press the "k" key. This deletes from the cursor to the end of the line, and so the combination of these two keys will always clear your text regardless of where your cursor begins. Sweet!
Often our cursor is at the end of the text in the prompt. When this is the case it's useful to know that you can just hold control and press the "u" key to delete everything to the left of the cursor all the way to the the beginning of the line. Also, similar to how you can jump the cursor to the beginning of a line with ctrl + a you can also jump your cursor to the end of the line with ctrl + e.
This was a quick post, and I want to keep it short and to the point. I'll just leave you with a bit of advice here: learn to love your command line! It's a very powerful tool that can do a lot. Learning shortcut keys like these can little by little add up to make you more productive, happier, and over a better developer. Enjoy!
The posts on this site are written and maintained by Jim Lynch. About Jim...