I'm working with a CSV that's just shy of 1 GB. I want to see the the file's structure and a sample of the data, but I don't want to open the entire file. How can I load the开发者_如何转开发 first few rows in Vim? If it makes a difference, I'm using MacVim.
I generally use a command like head
or tail
for seeing partial content of large files.
$head -10 <large file>
If you must do it from vim, use this:
:r !head -10 path/to/big.file
That would get the first 10 lines of big.file and insert them into the current buffer.
$ vim '+%!head -10' FILE
What that does is open the file, then execute :%!head -10
, which pipes the entire buffer through head -10
and replaces the contents of the buffer with the output from head
.
Mind the quotes, by the way.
If you are only wanting to preview and not edit the file, you can just use the less
or more
(see comment below) command. You can use spacebar and enter to read more of the file, and q to exit.
For anyone looking at how to do this on Windows, you can use the following in PowerShell to open the first 10 lines of a file in gvim
:
PS C:\MyCSVDirectory> Get-Content .\myfile.csv -TotalCount 10 > out | gvim out
Personally I prefer having it opened in gvim
, but if you'd like to have it open in terminal just use vim
instead. Also note that this will create a file called out
in the directory of your csv.
Alternatively you can use the following to simply print the lines in terminal:
PS C:\MyCSVDirectory> Get-Content .\myfile.csv -TotalCount 10
精彩评论