Take the 2-minute tour ×

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

share|improve this question

4 Answers 4

up vote 137 down vote accepted

will delete everything from your current line to the top of the file.

share|improve this answer
And kdgg will do the same except not delete the line in question. –  Rook Nov 12 '10 at 5:40
What exactly does the gg after delete mean? –  c-qjv0xfi Mar 6 '13 at 18:39
gg is a Vim shortcut - ":help gg" says: Goto line [count], default first line, on the first non-blank character |linewise|. If startofline' not set, keep the same column. –  Andy White Mar 7 '13 at 15:29
For those looking for it, dG will delete all lines at or below the current one. –  dimo414 Oct 11 '13 at 19:53
@dan3 I think the meaning of "top of the file" is pretty clear based on the question asked, but you are welcome to edit my answer if you want to, or you can create your own answer using whatever terminology you want. –  Andy White Feb 11 at 20:48


delete all lines above the current one.

share|improve this answer
This is a little confusing; it's actually moving the cursor up a line with k, then deleting the current line and up with dgg. –  dimo414 Oct 11 '13 at 19:54

: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.)

share|improve this answer
I tried TMTOWTDI but it just seems to leave me in insert mode without deleting anything? –  too much php Nov 12 '10 at 6:38
TMTOWTDI is not one of the More Than One Ways To Do It. –  Sarah Nov 12 '10 at 9:04
The only variant that works in VI too –  basin Jul 9 '12 at 7:38
Works in Solaris 10.X –  Carlos Sep 11 '12 at 12:17
tmtowtdi There's more than one way to do it (TMTOWTDI or TIMTOWTDI, pronounced "Tim Toady") is a Perl motto. –  vaichidrewar Oct 25 '13 at 23:13

d1G = delete to top including current line (vi)

share|improve this answer

Your Answer


