So I was trying to delete a portion of a command line command, but when I type backspace(delete option), it merely deselect the portion rather than delete the selected text as I expected. Is there a shortcut to use in the command line to delete the portion of the command that has been highlighted(selected?)
2 Answers
Terminal doesn't really care what you have selected, other than you can copy selected - it uses the cursor position for operations.
Opt ⌥ → or ← will jump the cursor one word at a time
Ctrl ⌃ W will delete the word immediately left of the cursor
Cmd ⌘ A or E will take you to the beginning or end of a line
Ctrl ⌃ U will delete to the beginning of the line
Ctrl ⌃ K will delete to the end of the line
There are many more - see TechRepublic - 20 Terminal shortcuts developers need to know
solution 1
- Use ConEmu - https://conemu.github.io/
- It allows you to delete selected text (for the current-entering command line)
- Note1: it requires you to: use keyboard
shift+arrow
to select, not mouse select - Note2: actually, you can delete selected text with mouse,
but first you need to click precisely & release the click, and to ensure the move of the vertical text caret is at the precise starting position of a char
-- the text caret must visibly be the vertical one, not the block one;
(and then drag from that precise starting position to the correct ending position);
otherwise you cannot del; idk why
- Note1: it requires you to: use keyboard
- It can move caret by mouse click.
- Note:
- some are language specific behavior, though most of the functionalities are presented in each language.
- eg: in powershell, you can click move the text caret; but in git.bash, you cannot. though both can delete highlighted text.
- Note:
- For Windows user only.
- It allows you to delete selected text (for the current-entering command line)
solution-workaround 2
- For Linux,
ctrl+w
deletes the word; - For Windows Powershell,
Ctrl+Backspace
deletes the word;
solution-workaround 3
To better modify your cmd like a normal editor, I recommend:
- write the line of cmd on a file,
- then use an IDE that supports directly send the whole line of cmd to your terminal.
-eg:workbench.action.terminal.runSelectedText
in Vscode (or other IDE like Intellij idea)
(or just write and exec in a bat/bash file...)