Thursday, October 31, 2013

Re: inserting filenames

On 2013-10-31 15:13, Chris Lott wrote:
> amalek-pages_01-Blot.png
> amalek-pages_02-New.png
> amalek-pages_03-Adipose.png
>
> I need to create a series of HTML sections like such:
>
> <section>
> <img width="550" height="650"
> src="pages/amalek-pages_02-New.png" alt="Blot">
> </section>
>
> Where do I start automating something like this with Vim?

I'd do the following:

1) read the list of filenames into Vim

:r !ls " on *nix systems
:r !dir /b " on Win32 systems

2) do a substitute over the range of lines you read in:

:%s@.*@<section>\r\t<img width="550" height="650"\rsrc="pages/&"
alt="Blot">\r</section>

You can adjust the regexp replacement as needed (the extra "\r"
before the src= might be some mail-goblin in the wires line-breaking
your email, rather than your desire for an actual line-break there).
If you need to update the alt-text too, you'd need to capture that
part and use it in the replacement:

:%s@^.\{-}_\d\+-\(.*\)\.png@<section>\r\t<img width="550"
height="650"\rsrc="pages/&" alt="\1">\r</section>

-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

---
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: