Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
like image 361
atman Avatar asked Jun 30 '17 12:06

atman


People also ask

What is the command to delete part of the line starting from the current cursor position?

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.

How do you delete the remaining portion of the line from the cursor position?

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.

How do you go to the beginning of a line in Vim?

Press 0 to go to the beginning of a line, or ^ to go to the first non-blank character in a line.


1 Answers

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.

like image 73
grepcake Avatar answered Oct 13 '22 00:10

grepcake