If I'm using terminal and typing in a line of text for a command, is there a hotkey or any way to clear/delete that line?
For example, if my current line/command is something really long like:
> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now>
Is there a hotkey or command to go from the above to:
>
?
Usually I will press the ↓ key, and if my current line is a brand new one on the history, that will clear it. But if I'm going through my command history via the ↑ key and start editing or using those commands, ↓ will only change the prompt to the next newest command in history, so it doesn't work here unless I press ↓ multiple times.
Ctrl + W will clear the word to the left.
I have the complete shortcuts list:
Another nice complete list:
TERINAL Shortcuts Lists:
Left Move back one character
Right Move forward one character
Ctrl+b Move back one character
Ctrl+f Move forward one character
Alt+Left Move back one word
Alt+Right Move forward one word
Alt+b Move back one word
Alt+f Move forward one word
Cmd+Left Move cursor to start of line
Cmd+Right Move cursor to end of line
Ctrl+a Move cursor to start of line
Ctrl+e Move cursor to end of line
Ctrl+d Delete character after cursor
Backspace Delete character before cursor
Alt+Backspace Delete word before cursor
Ctrl+w Delete word before cursor
Alt+w Delete word before the cursor
Alt+d Delete word after the cursor
Cmd+Backspace Delete everything before the cursor
Ctrl+u Delete everything before the cursor
Ctrl+k Delete everything after the cursor
Ctrl+l Clear the terminal
Ctrl+c Cancel the command
Ctrl+y Paste the last deleted command
Ctrl+_ Undo
Ctrl+r Search command in history - type the search term
Ctrl+j End the search at current history entry and run command
Ctrl+g Cancel the search and restore original line
Up previous command from the History
Down Next command from the History
Ctrl+n Next command from the History
Ctrl+p previous command from the History
Ctrl+xx Toggle between first and current position
Ctrl+w: move characters and (multiple) words left from your cursor to a ring buffer
Ctrl+y: insert last entry from your ring buffer and then you can use Alt+y to rotate through your ring buffer. Press multiple times to continue to "previous" entry in ring buffer.
An alternative to Ctrl+A, Ctrl+K is Ctrl+E, Ctrl+U.
I'm not sure if you love it but I use Ctrl+A (to go beginning the line) and Ctrl+K (to delete the line) I was familiar with these commands from emacs, and figured out them accidently.
Alt+# comments out the current line. It will be available in history if needed.
CTRL+R and start typing to search for previous commands in history. Will show full lines.
CTRL+R again to cycle.
or if your using vi mode, hit Esc followed by cc
to get back what you just erased, Esc and then p :)
Just to summarise all the answers:
In order to clean the whole line (2 different ways):
To delete the whole line no matter where the cursor is, you can use the kill-whole-line
command, but it is unbound by default. It can be bound to, for example, Ctrl+Alt+K by inserting
"\e\C-k": kill-whole-line
into your Readline init file (conventionally ~/.inputrc
).
Various remarks:
To avoid accidentally re-assigning a key sequence that is already in use for something else, you can check all your bindings with bind -P
. Check for the suggested binding with
bind -P | grep '\\e\\C-k'
INPUTRC
. If it is unset, the default is ~/.inputrc
, or (if that doesn't exist) /etc/inputrc
. Notice that if you have ~/.inputrc
, /etc/inputrc
will be ignored.Ctrl+A, Ctrl+K to wipe the current line in the terminal. You can then recall it with Ctrl+Y if you need.
Add to the list:
In Emacs mode, hit Esc, followed by R, will delete the whole line.
I don't know why, just happens to find it. Maybe it's not used for delete line but happens to have the same effect. If someone knows, please tell me, thanks :)
Works in Bash, but won't work in Fish.
Source: Stackoverflow.com