How do you delete all text above a certain line
How do you delete all text above a certain line. For deletion below a line I use "d shift g"
Solution 1:
dgg
will delete everything from your current line to the top of the file.
d
is the deletion command, and gg
is a movement command that says go to the top of the file, so when used together, it means delete from my current position to the top of the file.
Also
dG
will delete all lines at or below the current one
Solution 2:
:1,.d
deletes lines 1 to current.:1,.-1d
deletes lines 1 to above current.
(Personally I'd use dgg
or kdgg
like the other answers, but TMTOWTDI.)
Solution 3:
kdgg
delete all lines above the current one.
Solution 4:
Providing you know these vim commands:
1G -> go to first line in file
G -> go to last line in file
then, the following make more sense, are more unitary and easier to remember IMHO:
d1G -> delete starting from the line you are on, to the first line of file
dG -> delete starting from the line you are on, to the last line of file
Cheers.
Solution 5:
d1G
= delete to top including current line (vi)