Search code examples
terminalzshoh-my-zsh

How to delete from current position to the beginning of the line?


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 

Solution

  • 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.