How do I delete everything from my cursor current position to the beginning of the line?
For example, say I'm running npm run start and my cursor is positioned just before start? How do I remove npm run with a keyboard shortcut leaving start?
~ npm run █start
I'm expecting something like how ctrl+w deletes the last word. Similarly, is there a shortcut to delete from current cursor position to the beginning of the line?
I'm using oh-my-zsh shell on Mac 10.12.
EDIT: Some shortcuts here -
move to the start of line - ctrl + a
move to the end of line - ctrl + e
clear the word previous to the cursor - ctrl + w
clear text from cursor to the start of line - ctrl + r, by adding "bindkey \^R backward-kill-line" to your zshrc file
clear text from cursor to the end of line - ctrl + k
clear full line - ctrl + u
To delete part of a word, position the cursor on the word to the right of the part to be saved. Type dw to delete the rest of the word.
As others have mentioned: you can use d$ or D ( shift - d ) to delete from the cursor position until the end of the line. What I typically find more useful is c$ or C ( shift - c ) because it will delete from the cursor position until the end of the line and put you in [INSERT] mode.
Press 0 to go to the beginning of a line, or ^ to go to the first non-blank character in a line.
Use Ctrl+U
unix-line-discard (C-u) Kill backward from point to the beginning of the line. The killed text is saved on the kill-ring.
It is also useful to see man bash.
In case you use zsh, you should add this line: bindkey \^U backward-kill-line to your .zshrc. See this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With