How I can delete in VIM all text from current line to end of file?

user810430 picture user810430 · Nov 14, 2011 · Viewed 184.1k times · Source

I have very large files (more than 10Gb). I need only some lines from the top of the file. Is it possible (in vim) to delete the rest of the file (from current line to the end of file)?

Answer

Ed Guiness picture Ed Guiness · Nov 14, 2011

dG will delete from the current line to the end of file

dCtrl+End will delete from the cursor to the end of the file

But if this file is as large as you say, you may be better off reading the first few lines with head rather than editing and saving the file.

head hugefile > firstlines

(If you are on Windows you can use the Win32 port of head)