Reputation: 11499
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)?
Upvotes: 283
Views: 261084
Reputation: 451
:.,$d
This will delete all content from current line to end of the file. This is very useful when you're dealing with test vector generation or stripping.
Upvotes: 45
Reputation: 309
I use the following steps to do the same-
Esc
.V
.G
i.e Shift + g
to select the text from the cursor to the end of the file .x
to delete the selected text .Upvotes: 9
Reputation: 1083
Go to the first line from which you would like to delete, and press the keys dG
Upvotes: 96
Reputation: 35287
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
)
Upvotes: 471
Reputation: 1692
Just add another way , in normal mode , type ctrl+v
then G
, select the rest, then D
, I don't think it is effective , you should do like @Ed Guiness, head -n 20 > filename in linux.
Upvotes: 1