Large file - Opening n head lines

7 views
Skip to first unread message

Ni Va

unread,
Mar 17, 2022, 4:41:08 AM3/17/22
to vim_use
Hi All,

Is it possible to open a Large File Vim but just only few beginning lines of it, edit one of these 50 first lines and then save and quit ?

Thank you
NV

Lifepillar

unread,
Mar 17, 2022, 5:55:24 AM3/17/22
to vim...@googlegroups.com
On 2022-03-17, Ni Va <niva...@gmail.com> wrote:
> Is it possible to open a Large File Vim but just only few beginning lines
> of it, edit one of these 50 first lines and then save and quit ?

I don't think that is possible with Vim without the help of some
pre/post-processing tool, but... Vim can edit pretty large files
relatively quickly, if set up properly. Have you tried playing with
Vim's settings already?

Of course, all depends on what "large" and "quick" mean to you. And
I believe that the line length of the edited files is also an important
factor.

Life.

Steve Litt

unread,
Mar 17, 2022, 6:38:00 AM3/17/22
to vim...@googlegroups.com
Ni Va said on Thu, 17 Mar 2022 01:41:08 -0700 (PDT)

>Hi All,
>
>Is it possible to open a Large File Vim but just only few beginning
>lines of it, edit one of these 50 first lines and then save and quit ?

head -n 50 bigfile.txt | vim -
# NOTE: Save as bigfile.new
tail +51 bigfile.txt >> bigfile.new
# NOTE: bigfile.new is now your edited file.

If you do it often, you can put it in a shellscript, and can even
rename the original to .bak.

HTH

SteveT

Steve Litt
March 2022 featured book: Making Mental Models: Advanced Edition
http://www.troubleshooters.com/mmm

M

unread,
Mar 17, 2022, 7:08:11 AM3/17/22
to vim...@googlegroups.com

чт, 17 мар. 2022 г. в 11:41, Ni Va <niva...@gmail.com>:
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/65df570f-36f5-415b-8b07-1111b4bda4f6n%40googlegroups.com.

Inserting data, in general case (i.e. if the size may change), is non-trivial. That is, one has to append a copy of the original file's tail and then flush everything to disk again.So even if you do

    :read !head -n 20 foobar.txt

and edit it, you still must do

    :saveas temp
    :!tail -n +21 foobar.txt >>temp
    :!mv temp foobar.txt

to create a new version. And it does not look like some gain to me.

Regards,
Matvey

Tim Chase

unread,
Mar 17, 2022, 8:01:31 AM3/17/22
to Ni Va, vim...@googlegroups.com
On 2022-03-17 01:41, Ni Va wrote:
> Is it possible to open a Large File Vim but just only few beginning
> lines of it, edit one of these 50 first lines and then save and
> quit ?

I don't think it's readily doable inside vim, but if I had such a
situation, I'd split it into the two portions like

$ sed -n -e '1,50w head.txt' -e '51,$w tail.txt' bigfile.txt

I could then edit head.txt easily and write it back out. I can then
recombine the pieces when done:

$ cat head.txt tail.txt > edited_bigfile.txt

-tim




Stan Brown

unread,
Mar 17, 2022, 9:51:47 AM3/17/22
to vim...@googlegroups.com

On 2022-03-17 02:55, Lifepillar wrote:
> On 2022-03-17, Ni Va <niva...@gmail.com> wrote:
>> Is it possible to open a Large File Vim but just only few beginning lines
>> of it, edit one of these 50 first lines and then save and quit ?
>
> I don't think that is possible with Vim without the help of some
> pre/post-processing tool, but... Vim can edit pretty large files
> relatively quickly, if set up properly. Have you tried playing with
> Vim's settings already?

What settings do you have in mind? I wasn't aware that Vim needed to be
set up differently for files of different sizes.

--
Stan Brown
Tehachapi, CA, USA
https://BrownMath.com

Charles Campbell

unread,
Mar 17, 2022, 1:50:49 PM3/17/22
to vim...@googlegroups.com
Vim doesn't "need" to be set up differently for large files. However,
options can be selected to make it faster.
See http://www.drchip.org/astronaut/vim/index.html#LARGEFILE for a
plugin that helps with large files.

Chip Campbell

Ni Va

unread,
Mar 17, 2022, 2:09:11 PM3/17/22
to vim...@googlegroups.com
Sorry for late answer, that was to modify a 50Go VMware .vmdk file. Just to modify disk space allocation. 😊

I tried this morning. Vim succeed to open but not to save and close. 

NV

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/jtqUuvOLZ5Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/177e85f5-d1a2-abd1-d2db-29e7b2fde5bf%40drchip.org.

Ni Va

unread,
Mar 17, 2022, 2:23:41 PM3/17/22
to vim...@googlegroups.com
Thank you Charles. Many years i use your largefile.vim. Thank you Charles. 😊 

Le jeu. 17 mars 2022 à 18:50, Charles Campbell <camp...@drchip.org> a écrit :

Ni Va

unread,
Mar 17, 2022, 2:24:53 PM3/17/22
to vim...@googlegroups.com
Thank you Steve i think you sum up the more efficient way. Thank you. Nicolas. 😉 

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/jtqUuvOLZ5Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.

Ni Va

unread,
Mar 17, 2022, 2:27:23 PM3/17/22
to vim...@googlegroups.com
Thank you all of you. 
Reply all
Reply to author
Forward
0 new messages