Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vi (gvim) command to indent the whole file ?

172 views
Skip to first unread message

Spendius

unread,
Nov 27, 2009, 5:32:48 AM11/27/09
to
Hi,

I'm trying to find a command to indent an XML file in vim/gvim.
Despite all the googling, I couldn't find any. Does it exist ?
For ex. from
<?xml version="1.0" encoding="ISO-8859-1"?><BOOK><TITLE>How do you
indent?</TITLE><AUTHOR><NAME>Kennedy</NAME><FIRSTNAME>Dick</
FIRSTNAME></AUTHOR></BOOK>

I'd like to get
<?xml version="1.0" encoding="ISO-8859-1"?>
<BOOK>
<TITLE>How do you indent?</TITLE>
<AUTHOR>
<NAME>Kennedy</NAME>
<FIRSTNAME>Dick</FIRSTNAME>
</AUTHOR>
</BOOK>

simply by doing something like ":indent all" or ":1,$ indent"
or something similar...

Is it possible ?
Thanks.
Sp

Patrick Texier

unread,
Nov 27, 2009, 9:15:20 AM11/27/09
to
Le Fri, 27 Nov 2009 02:32:48 -0800 (PST), Spendius a �crit�:

> simply by doing something like ":indent all" or ":1,$ indent"
> or something similar...

In normal mode, it is the = operator:

gg=G
--
Patrick Texier

vim:syntax=mail:ai:ts=4:et:tw=72

Mikolaj Machowski

unread,
Nov 27, 2009, 11:22:56 AM11/27/09
to
Spendius scripsit:

> Hi,
>
> I'm trying to find a command to indent an XML file in vim/gvim.
> Despite all the googling, I couldn't find any. Does it exist ?
> For ex. from
><?xml version="1.0" encoding="ISO-8859-1"?><BOOK><TITLE>How do you
> indent?</TITLE><AUTHOR><NAME>Kennedy</NAME><FIRSTNAME>Dick</
> FIRSTNAME></AUTHOR></BOOK>
>
> I'd like to get
><?xml version="1.0" encoding="ISO-8859-1"?>
><BOOK>
> <TITLE>How do you indent?</TITLE>
> <AUTHOR>
> <NAME>Kennedy</NAME>
> <FIRSTNAME>Dick</FIRSTNAME>
> </AUTHOR>
></BOOK>

:%s/></>\r</g
gg=G

m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078
CLEWN - http://clewn.sf.net

Peter Gordon

unread,
Nov 27, 2009, 3:39:47 PM11/27/09
to
Spendius <spen...@muchomail.com> wrote in news:f8578bd1-39c2-4813-8297-
2f45d9...@p8g2000yqb.googlegroups.com:

I use a utility called tidy to format XML.
It is a UNIX program which has been ported
to win32. I have forgotten where I obtained
the port of it which I use. Google for
tidy.exe.

It requires a config file. I call mine
tidyXML.txt. It contains:

char-encoding: utf8
indent: auto
input-xml: yes
output-xml: yes
wrap: 132
indent-spaces: 4
markup: yes
quiet: yes
show-warnings: yes
numeric-entities: yes
quote-marks: yes
quote-nbsp: yes
quote-ampersand: no
break-before-br: no
uppercase-tags: no
uppercase-attributes: no

I then execute it with a small script in
a file called tidyXML.vim. This file contains:

%!C:/Bin/tidy.exe -config C:/Bin/Scripts/tidyXML.txt

To execute it, from within gvim, I use:
:so C:\Bin\Scripts\tidyXML.vim

You will need to read the documentation for tidy and
make the modifications you require. Also you will need to
change the paths to the files.

0 new messages