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".
Try d0
. 0
denotes the beginning of the line.
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.
TLDR: The easiest way is to do the following
- use the navigate mode
- set the cursor at whatever line you want
- press dgg - this will remove everything from cursor to the beginning
- press dG - this will remove all the lines from cursor till the end of the doc.
But why?
gg - goes to the begin of the document
G - navigates at its very end
d - delete mode
I was also looking for some combinations with the notation of d and line number, and when you are editing huge files like GB in size I found it bit annoying. Like to remove first 3 lines you need to do this :0,d3, but when the docu is over 1mln lines its tough for my eyes to read this crap...