On 2020-10-12, L A Walsh wrote:
> On 2020/10/10 23:10, Gary Johnson wrote:
> >On 2020-10-10, L A Walsh wrote:
> >>:%s/>/>^M/g
> >>:%s/<\([^>]\+\)>\n\([^>]\+\)<\/\1>/<\1>\2<\\\1>
> >
> >I don't know of a way to do that with one command, ....
> >then execute the following
> >normal-mode command.
> >
> > gg=G
> ---
> close enough, as I gave 'ggap' as an example for text.
>
> >You might also search the web for HTML Tidy. I think it will
> >reformat an HTML file.
> ---
> yeah, but it was xml and main requirement was to run
> pretty much in (g)vim. You got like 100% for my original
> question! But ran into a quirky special case that fails with
> normal vim indenting as well (works if I split all
> lines 1st), but if some of the close tags are on same line
> as open, doesn't seem to unindent...
>
> Example, starting with:
> <xml>
> <totalbytes>2952962267<\totalbytes>
> <image index="1">
> <dircount>13363<\dircount>
> <filecount>64267<\filecount>
> <totalbytes>11707704502<\totalbytes>
> <creationtime>
> <highpart>0x01cb8936<\highpart>
> <lowpart>0x131f339a<\lowpart>
> </creationtime>
> <lastmodificationtime>
> <highpart>0x01cb8950<\highpart>
> <lowpart>0xbc4d774b<\lowpart>
> </lastmodificationtime>
> <doors>
> <arch>9<\arch>
> <hal>acpiapic<\hal>
> <languages>
> <language>en-us<\language>
> <default>en-us<\default>
> </languages>
> <systemroot>doors<\systemroot>
> </doors>
> <hardlinkbytes>4497873056<\hardlinkbytes>
> </image>
> </xml>
>
> Running '=' over that, (filetype=xml, syn=xml) using expand tab, I get:
>
> <xml>
> <totalbytes>2952962267<\totalbytes>
> <image index="1">
> <dircount>13363<\dircount>
> <filecount>64267<\filecount>
> <totalbytes>11707704502<\totalbytes>
> <creationtime>
> <highpart>0x01cb8936<\highpart>
> <lowpart>0x131f339a<\lowpart>
> </creationtime>
> <lastmodificationtime>
> <highpart>0x01cb8950<\highpart>
> <lowpart>0xbc4d774b<\lowpart>
> </lastmodificationtime>
> <doors>
> <arch>9<\arch>
> <hal>acpiapic<\hal>
> <languages>
> <language>en-us<\language>
> <default>en-us<\default>
> </languages>
> <systemroot>doors<\systemroot>
> </doors>
> <hardlinkbytes>4497873056<\hardlinkbytes>
> </image>
> </xml>
>
> ----
> Seems if I have some closing tags on same line it doesn't
> unindent (happens in normal insert as well). Seems unrelated
> to the method you gave. I have seen the indent problem in other
> languages as well, but am stymied coming up with
> an example off the top of my head.
>
> To emphasize, if all the tags (open+close) are on their
> own line, it works just fine. But when some matching tags
> are on same line, I get mixed/weird results.
>
> Anyone seen such fun? And thanks again gary, for the '=',
> don't recall ever seeing that.
You're welcome.
I am no expert in XML, but I thought that closing tags began with
a slash, not a backslash; that is, with "</", not "<\". Apparently
Vim's XML indent plugin thinks so, too.
I copied your example to another buffer, set its filetype to "xml",
replaced all backslashes with slashes, and executed "gg=G". The
result was indented as I think you and I expected it to be, like
this:
<xml>
<totalbytes>2952962267</totalbytes>
<image index="1">
<dircount>13363</dircount>
<filecount>64267</filecount>
<totalbytes>11707704502</totalbytes>
<creationtime>
<highpart>0x01cb8936</highpart>
<lowpart>0x131f339a</lowpart>
</creationtime>
<lastmodificationtime>
<highpart>0x01cb8950</highpart>
<lowpart>0xbc4d774b</lowpart>
</lastmodificationtime>
<doors>
<arch>9</arch>
<hal>acpiapic</hal>
<languages>
<language>en-us</language>
<default>en-us</default>
</languages>
<systemroot>doors</systemroot>
</doors>
<hardlinkbytes>4497873056</hardlinkbytes>
</image>
</xml>
Regards,
Gary
--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201013063405.GA16884%40phoenix.
Monday, October 12, 2020
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment