How can I clear the current line of the Windows command prompt?
Solution 1
The Escape (Esc
) key will clear the input line.
In addition, pressing Ctrl+C
will move the cursor to a new, blank line. This may be helpful as the input you just reviewed remains visible while you type the new command.
Solution 2
Aside from the two that Myyrddin covered - Esc
and Ctrl+C
- there are also two more shortcuts related to clearing the current input in CMD.
Ctrl+Home
will clear all characters in the input before the cursor (equivalent to Ctrl+U
in Bash)
Ctrl+End
will clear all characters in the input after the cursor (equivalent to Bash's Ctrl+K
)
Both are fairly useful and, once internalised and gotten used to, could speed up editing in CMD by quite a bit.
Related videos on Youtube
Sundar_Mob
Updated on September 18, 2022Comments
-
Sundar_Mob over 1 year
Crashing while creating an instance of URLSessionTask with the completion handlers
func sessionTaskPostRequest (_ urlRequest : URLRequest , responseHandler: @escaping ResponseHandler) -> URLSessionTask { // 5 let sesstionTask : URLSessionTask = networkSession.dataTask(with: urlRequest, completionHandler: { (data : Data? , urlResponse : URLResponse? , error : NSError? ) in var json: NSDictionary! do { json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions()) as? NSDictionary } catch { print(error) } // Did the JSONObjectWithData constructor return an error? If so, log the error to the console if(error != nil) { responseHandler (false , nil , error , nil) } else { // The JSONObjectWithData constructor didn't return an error. But, we should still // check and make sure that json has a value using optional binding. if let parseJSON = json { let errorJSON = parseJSON ["Err"] as! String if !errorJSON.isEmpty { responseHandler (false , nil , nil , errorJSON) }else { responseHandler (true , parseJSON , nil , nil) } print("Succes: \(parseJSON)") } else { // Woa, okay the json object was nil, something went worng. Maybe the server isn't running? let jsonStr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue) responseHandler (false , nil , error , "Error could not parse JSON") print("Error could not parse JSON: \(jsonStr)") } } } as! (Data?, URLResponse?, Error?) -> Void) return sesstionTask }
And created a type alias for response handler that returns the response JSON Object . Type alias as follows
typealias ResponseHandler = (_ successFlag :Bool , _ data : NSDictionary? , _ errorObject : NSError? , _ errorString : String?) -> Void
-
barlop about 12 years@myrddim has it but that aside, some poor alternatives are keep tapping up until you have something short then hold backspace. another one is make the command be a bad command or filename, or rather, an "'sdfd' is not recognised as an internal or external command" so move the cursor a bit with left arrow and just tap a letter or don't and just tap a letter at the end, mess up the cmd input, then hit ENTER, get that error and the next line will be blank.
-
iglvzx about 12 years@barlop That is indeed a poor workaround! It only takes one keystroke. If you can't use the
Esc
key, you could use AutoHotkey to simulate it. -
Avt over 7 yearsIn what line do you have a crash
-
Sundar_Mob over 7 years} as! (Data?, URLResponse?, Error?) -> Void) in this line
-
-
iglvzx about 12 yearsAnd if you want to clear the whole screen, you can use the
cls
command. :) -
Milo Wielondek over 11 yearsAs a side note, on UNIX it's
ctrl+u
. -
Myrddin Emrys over 11 yearsWhich would be relevant if the question wasn't specifically targeted at the Windows 7 command prompt. :-) Also, I believe this is shell specific, as I am reasonably certain some shells have the same behavior as Windows when pressing
Ctrl+C
. -
FutuToad almost 10 yearsand how do you remove all the text so you can't scroll up?
-
Myrddin Emrys almost 10 years@FutuToad the
clear
command will do what you ask. -
CJ7 almost 8 years@MyrddinEmrys on Windows it is
cls
-
SexyBeast almost 8 yearsNote: the
CTRL+C
command will also exit any command line session you are having, i.epython
, and return you back to the command line environment. -
Myrddin Emrys almost 8 years@AttitudeMonger That is a common command line utility behavior, but is not actually a feature of the command line itself. Many command line utilities do not exit on receipt of the Ctrl+C keystroke. It will not exit any command, but it is accurate to say it exits many commands.
-
SexyBeast almost 8 yearsOh I see. Thanks, I did not know that!
-
Ervin over 7 yearsI use Ctrl + backspace to clear the current line, or ctrl + Home, if you press just
home
you go to the start of the line -
Myrddin Emrys over 7 yearsI didn't know about these keystrokes; thank you. May you get the upvotes you deserve.
-
uranusjr almost 7 yearsSame here. Being used to Bash I always wanted those. OP is my savior.
-
balki almost 6 yearsIs it possible to set it to
ctrl+u
like in windows. I have to lift my hand to reachesc
-
Scott - Слава Україні over 5 yearsFrom bash(1): (Ctrl)+(X), (Rubout) is defined to be backward-kill-line; i.e., kill backward to the beginning of the line; i.e., the same as (Ctrl)+(Home) in Windows CMD. “Rubout” may be Backspace or Delete, so try (Ctrl)+(X), (Backspace) and (Ctrl)+(X), (Delete). Also, (Ctrl)+(U) is unix-line-discard; i.e., kill backward from the insertion point (cursor) to the beginning of the line; i.e., also the same as (Ctrl)+(Home). (Ctrl)+(K) is defined to be kill-line; i.e., kill the text from the insertion point to the end of the line; i.e., the same as (Ctrl)+(End) in Windows CMD.
-
Scott - Слава Україні almost 5 yearsJust to be clear: (Ctrl)+(U) is a long-standing, general feature of Unix. It works in old, non-Linux, non-GNU, non-bash systems; it works in
vi
; it works if you docat > file123
. The others are specific to the bash command line. -
ennth over 3 yearsctrl+u on mac, thank you!
-
Admin about 2 yearsShift+Home and Shift+End selects the same as above, instead of deleting it.