> I'm a new user of vim and am currently evaluating it for my uses. I'm coming
> from BBEdit. One of the features of BBEdit that I've found useful is the
> 'persistent include.'* It's mostly used for HTML. The idea behind it is that
> you can specify a file in an HTML comment, and when you 'update' the document,
> the file's contents are included in your HTML document, between the persistent
> include comments. It looks like this:
>
> <!-- #bbinclude "filename" -->
> file contents that are inlined.
> <!-- end bbinclude -->
>
> *Only* the lines in between the include comments are replaced with included
> file. If the included file changes and you update the main file again, the
> contents are updated. The real power of this comes from when the included
> file is a shell script, which you can pass options too.
>
> Sorry for the long winded description. My question is this: Is there
> functionality in vim for something like this? If not, is there a pre-existing
> script that replicates this?
I don't know of anything pre-existing, but I whipped up this
which reads in the file:
:g/<!-- #bbinclude "[^"]*" -->\_.\{-}<!-- end bbinclude -->/let
fname=matchstr(getline('.'),'<!-- #bbinclude "\zs[^"]*\ze"
-->')|exec '+,/<!-- end bbinclude -->/-!cat '.fnameescape(fname)
or, if you want to exec it as a script
:g/<!-- #bbinclude "[^"]*" -->\_.\{-}<!-- end bbinclude -->/let
fname=matchstr(getline('.'),'<!-- #bbinclude "\zs[^"]*\ze"
-->')|exec '+,/<!-- end bbinclude -->/-!'.fnameescape(fname)
It's pretty rigid on the tag-formatting (exact-matches, spacing
matters, etc), but the regexps can be tweaked to be more
permissive. You can also tweak it if you want for alternate tags
("<!-- #viminclude ... -->").
You don't mention how these replacements are triggered (it might
have been in the bbedit website)...on-read? on a key-press?
on-write? These can be set up with an autocmd or mapping
depending on what you want.
-tim
--
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
No comments:
Post a Comment