Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How could I erase the whole word with using Ctrl-Backspace in Windows XP command line? Is it possible at all?

share|improve this question

6 Answers 6

CMD or Powershell doesn't have a native shortcut to delete the word to the left or right. Here are some examples of what each platform can do. What you could probably do to make it a little easier is use the shortcut to move to the beginning or end of a word and start deleting or backspacing to delete the word.

share|improve this answer

AHK Code to replicate Ctrl+Backspace functionality to delete previous word. What this does is selects the previous word with Ctrl+Shift+Left, and then presses delete. Works well enough for me in notepad, and other programs, though is bit wonky in win7. Can't confirm for terminal right now.

^BackSpace:: ;;Delete previous word
    Send ^+{Left}{Del}
 Return
share|improve this answer

try this instead:

^BackSpace:: ;;Delete previous word
Send ^+{Left}
Loop, 500 {
    Send {Del}
}
Return

it modified the previous answer by sending 500 deletes after positioning at the previous word. 500 may be excessive, but so what.

this is for autohotkey (http://www.autohotkey.com/) and works in a cmd window, I put it in my cmd window specific section with the paste code like this:

#IfWinActive ahk_class ConsoleWindowClass
; Paste in command window
^V::
Send !{Space}ep
return

^BackSpace:: ;;Delete previous word
Send ^+{Left}
Loop, 500 {
    Send {Del}
}
Return

#IfWinActive
share|improve this answer
    
What if the cursor was in the middle of a line and there are more words following the previous word? –  Codism Jan 22 at 21:14

Been wanting this a long time! :) Just wanted to +1 idea of using AHK, and suggest an improvement to the script for it. I like ^W for word erase, as in linux shells, so I'm glad to have found this.

The first script didn't work for me in CMD (jumps back a word then erases the first character, not the whole word). The next script above wasn't quite ideal either, so rather than looping e.g. 500 times sending Del keystrokes (which I found sometimes spills over and sends deletes into another window if you change focus, eek), instead there is CMD's F4 functionality: Prompts for a character and deletes up to that char. So, jump a word back with ctrl-Left, then F4 followed by Space, to delete up to a space. The only minor downsides are that (a) it flashes the prompt box briefly, and (b) repeated word erases leave a pile of spaces (harmless but a bit unattractive). I also wanted ^U (erase to start of line) and ^A/^E/^F/^B word/char movement like linux shells (even though they already exist in CMD, I touch type so prefer not to move my hands away from the main keyboard). :) I also kept in David Hoppe's great ^V for paste.

Thus:

#IfWinActive ahk_class ConsoleWindowClass
; Paste in command window
^V::
Send !{Space}ep
return

; was ^BackSpace, I prefer ^W a la linux
^W:: ;;Delete previous word
Send ^+{Left}
Send {F4}{Space}
Return

^U::   ;;erase to start of line
Send ^{Home}
Return

^A::   ;;move to start of line
Send {Home}
Return

^E::   ;;move to end of line
Send {End}
Return

^F::   ;; move one char forward
Send {Right}
Return

^B::   ;;move one char back
Send {Left}
Return
#IfWinActive
share|improve this answer

I think it should be better if select more Shift + Left, because it can select the backspce after/before the word. for example:

^w:: ;;Delete previous word
    Send ^+{Left}+{Left}
    Loop, 5 {
        Send {Del}
    }
Return
!d:: ;; Delete backward word
    Send ^+{Right}+{Rigt}
    Loop, 5 {
        Send {Backspace}
    }
Return
share|improve this answer

It's not possible natively in the Windows command prompt.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.