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

FileVimText

File Problem Overview


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)?

File Solutions


Solution 1 - File

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)

Solution 2 - File

Go to the first line from which you would like to delete, and press the keys dG

Solution 3 - File

:.,$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.

Solution 4 - File

I use the following steps to do the same-

  1. Make sure you are in the normal mode by pressing Esc .
  2. Enter the Visual mode by pressing V .
  3. Press G i.e Shift + g to select the text from the cursor to the end of the file .
  4. Now press x to delete the selected text .

Solution 5 - File

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.

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
Questionuser810430View Question on Stackoverflow
Solution 1 - FileEd GuinessView Answer on Stackoverflow
Solution 2 - FileJames MathewView Answer on Stackoverflow
Solution 3 - FileChakravarthiView Answer on Stackoverflow
Solution 4 - FilePrakhar de AnandView Answer on Stackoverflow
Solution 5 - Filefrank.linView Answer on Stackoverflow