RE: Is there a "xml formatter"?
>I don't have much luck with that technique.
> Op woensdag 30 mei 2007, schreef wangxu:
> > I want to have this function:
> > formatting my xml file automatically.
> > or,indent xml element and attributes.
> > is there any plugin like this?
> > thanks!
> Well, if you're on a unix machine with xmllint installed, you
> could do the following:
> setlocal equalprg=xmllint\ --format\ -
> and then use gg=G to reformat the entire document.
If xmllint believes the xml isn't quite valid then it screws it up with
error messages and such.
I wrote this little function to do it for me. Works well enough.
Basically, I either run the command
Or, visually select some rows and run the command.
function! Format_SGML() range
" Add a new line to the bottom of the mark to be removed later
silent! exec "ma z"
" Add a new line above the mark to be removed later
put! = ''
silent! exec "ma y"
" Put each tag on a newline
" Reformat using Vim's indenter
exec 'normal! '.(line("'z")-line("'y")+1).'=='
" Delete the additional lines added
silent! exe "norm! 'ydd'zdd"
command! -range=% -nargs=0 FormatSGML <line1>,<line2>call Format_SGML()
At least you have some additional options now.