How do you delete all text above a certain line

Vim

Vim Problem Overview


How do you delete all text above a certain line. For deletion below a line I use "d shift g"

Vim Solutions


Solution 1 - Vim

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 - Vim

: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 - Vim

kdgg

delete all lines above the current one.

Solution 4 - Vim

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 - Vim

d1G = delete to top including current line (vi)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser339108View Question on Stackoverflow
Solution 1 - VimAndy WhiteView Answer on Stackoverflow
Solution 2 - VimephemientView Answer on Stackoverflow
Solution 3 - VimRookView Answer on Stackoverflow
Solution 4 - VimLian SebeView Answer on Stackoverflow
Solution 5 - VimmikiedbaView Answer on Stackoverflow