Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #18 - Cleanup your HTML

Created: February 25, 2001 19:59 Complexity: advanced Author: scrott--AT--users.sourceforge.net Version: 5.7 Karma: 50/29 Imported from: Tip#18

From Johannes Zellner on the vim list:


You can use vim's makeprg and equalprg to clean up HTML. First download html tidy from http://www.w3.org/People/Raggett/tidy/. Then use the following commands.


vim6?

exe 'setlocal equalprg=tidy -quiet -f '.&errorfile

setlocal makeprg=tidy -quiet -e %


vim5?

exe 'set equalprg=tidy -quiet -f '.&errorfile

set makeprg=tidy -quiet -e %


At this point you can use make to clean up the full file or you can use = to clean up sections.


:help =

:help equalprg

:help makeprg

Comments

There is also Jtidy (Java implementation of tidy):

http://sourceforge.net/projects/jtidy/

scrott--AT--users.sourceforge.net , May 2, 2001 23:05


Vim 6.0 comes with a Tidy compiler plugin for use in quickfix mode - $VIMRUNTIME/compiler/tidy.vim

djkea2--AT--mugca.cc.monash.edu.au , January 11, 2002 5:01


Any hints or tips on how to use the tidy.vim plugin?

andy_todd--AT--yahoo.com , April 23, 2002 19:11


The current version of C Tidy is now at http://tidy.sourceforge.net/ ;

creitzel--AT--rcn.com , July 4, 2002 12:02


Make that http://tidy.sourceforge.net/

creitzel--AT--rcn.com , July 4, 2002 12:03


To use the included compiler script, run `:compiler tidy`. For more info, see :h quickfix and :h compiler-select.

If you are using tidy.vim under WinNT (not sure about 9x), you need to set your shellpipe=2> or else Vim won't see the output from tidy. Apparently these Unix tools write output to stderr instead of stdout and Vim isn't configured by default to handle this situation.

william--AT--knowmad.com , August 15, 2002 6:25


just start with vim using 6.2 (mandrake 10 .rpm) need add backslaces like in the tidy.vim file don't know but for me works just with the command:

setlocal makeprg=tidy\ -quiet\ -m\ -utf8\ %

and then:

make


hecchan--AT--diazcalvo.com , April 29, 2004 21:07


vim 6.3 intends html very well when I put the line

filetype plugin indent on

into my personal ~/.vimrc (or ~\_vimrc) file. I also think that html-tidy is not able to indent only parts of a HTML file. Therefore, I do not use it as equalprg.

I use html-tidy only in order to check if my HTML document is well formed. Therefore, I create a ~/.vim/after/ftplugin/html.vim (or ~\vimfiles\after\ftplugin\html.vim or an html.vim placed in the directory that appears last when typing :set runtimepath?) and put into it (among other things) the lines:

setlocal makeprg=tidy\ -quiet\ -errors\ % setlocal errorformat=line\ %l\ column\ %v\ -\ %m

I have found that the errorformat option must be adapted as shown in order to be able jump through the error list by means of :cn and :cp etc.

michaelis--AT--tcnet.ch , March 27, 2005 5:00


Tidy can be used for just a portion of the document by using the --show-body-only flag. For instance, on using vim6 on OSX the above command could be rewritten as:

exe 'setlocal equalprg=tidy\ -quiet\ -i\ --show-body-only\ true\ -f\ '.&errorfile

the -i indents, that is optional

The rest of the tidy options can be found here: http://cvs.sourceforge.net/viewcvs.py/tidy/tidy/htmldoc/Attic/quickref.html?rev=1.15

Anonymous , March 21, 2006 11:19


Advertisement