file subset of file updated

16 views
Skip to first unread message

Bee

unread,
Jul 31, 2019, 3:15:11 PM7/31/19
to vim_use
Does vim have the ability to reference a file made of files?

file A is a subset of file B
file A = text
file B = file A plus more text

When file A is updated opening file B shows the changes

Tim Chase

unread,
Jul 31, 2019, 3:29:05 PM7/31/19
to Bee, vim...@googlegroups.com
Not out of the box AFAIK.

It would help to know the type of inclusion: are these C-style
#include files? or are they LaTeX with \input{filename} style
includes? And what tooling are you using to generate the resulting
file you want to view?

My first inclination would be to lean on make(1) to generate the
output file based on the input files (updating based on their
changes), then create an autocmd (`:help autocmd` and `:h
BufWritePost`) that runs :make when you save and optionally loads the
results into a preview window.

-tim


Erik Christiansen

unread,
Aug 1, 2019, 5:47:36 AM8/1/19
to vim_use
On 31.07.19 12:15, Bee wrote:
> Does vim have the ability to reference a file made of files?
>
> file A is a subset of file B
> file A = text
> file B = file A plus more text

In my experience, Vim edits multiple files, one at the time, and you can
switch between them. Where you have created separate files, there you
have separate files.

You could, though, make a simple text file listing the filenames of
those fragments, one per line, open it, put the cursor on a desired section,
and type gf - bingo!, you're in a document fragment.

> When file A is updated opening file B shows the changes

Is there a strong reason why the separate text sections required to
behave as a single document must be separate files? Vim has folding,
which allows me to maintain a document, today 28,794 lines long,
presenting it initially as one page of section headings. Scrolling the
cursor down to any particular heading and hitting <right arrow>¹ unfolds
that section.

That keeps currently uninteresting sections out of my hair, yet
associates all the parts of the document, without the need for another
file to list the parts of a fragmented document, in bits, here and
there.

It is, admittedly, not quite so convenient for making up several
documents from different selections of common fragments. However, when
folded, a section can be cut as a single line, and similarly pasted in a
new position in the document. That provides all the reordering power of
a fragmented document, without the hassle of inventing sticky tape to
put them together.

And the most powerful foldmethod requires the addition of delimiters.
But if the less intrusive methods did not suffice, then the delimiters
can be removed with a line of awk or sed, without effort. That is, after
all, the spirit of *nix: Each tool does one thing well, and the OS is
the glue which makes them into your custom machine.

¹ Emacs might have such a fragment linking mechanism, as it's a capable
OS - it just needs a good editor, as has been noted by others.

Erik
Reply all
Reply to author
Forward
0 new messages