Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vi to delete from the beginning of the line till the cursor

How can we use vim to delete characters from the beginning of the line till the cursor. Say, we have a string "hello world" while the cursor is on "w". How can we delete from "h" till "w".

like image 502
blue123 Avatar asked Jan 09 '13 15:01

blue123


People also ask

What hotkey can I use to delete a line from the beginning to the cursor?

Place the text cursor at the beginning of the line of text. On your keyboard, press and hold the left or right Shift and then press End to highlight the entire line. Press Delete to delete the line of text.

Which vi command deletes a line from cursor to end of line?

The command d$ (note, that's a dollar sign, not an 'S') will delete from the current cursor position to the end of the current line. D (uppercase D) is a synonym for d$ (lowercase D + dollar sign).

How do I delete all lines starting with vi?

To remove all lines containing a particular string in the vi or Vim text editors, you can use the g command to globally search for the specified string and then, by putting a "d" at the end of the command line, specify that you want all lines containing the specified string deleted.

Which vi command would you use to delete an entire line of text?

To delete a line in Vi or Vim, switch to normal mode first. If you're into command mode or insert mode, you can switch back to normal mode by pressing Escape. Highlight the line that you want to delete, then hit dd or D on the keyboard. The editor will automatically remove the whole line from the file.


2 Answers

Try d0. 0 denotes the beginning of the line.

like image 121
Lars Kotthoff Avatar answered Sep 21 '22 15:09

Lars Kotthoff


I believe that the following should work (d^):

d^ 

This assumes that you only want to delete to the h even if there is white space in front of it. It will leave the white space.

like image 40
Mark Wilkins Avatar answered Sep 21 '22 15:09

Mark Wilkins