[PHP-DOC] Mildly OT: VIM 6.x (alpha) has folding From: Jesus Castagnetto (jmcastagnetto <email protected>)
Date: 11/13/00

After several months I went to www.vim.org and found that 6.x was out
for testing.

Got it, compiled it and the folding worked like a charm w/ the PHP
source code. Then I found (from info in the VIM devel list) a
replacemente syntax for XML (xml.vim) that can be used for folding XML
docs too. There is a DocBook syntax file, but looking at it seems to
only have definitions related to highlighting not folding.

You can pick the xml.vim replacement to the one in the 6.0l alpha
release (it is a lowercase "L") from:

        http://www.zellner.org/vim/syntax/

Then you will just need to use ":set foldmethod=syntax", and voila!
you are now in fold editing mode.

In my .vimrc I use now:

" for XML/XSL files
au BufRead,BufWrite,BufNewFile,FileReadPost *.xml,*.xsl retab! 4
au BufRead,BufWrite,BufNewFile,FileReadPost *.xml,*.xsl set
expandtab
au BufRead,BufWrite,BufNewFile,FileReadPost *.xml,*.xsl set
foldmethod=syntax foldcolumn foldlevel=2

If the three "au" lines above appear wrapped in your mail, do not
forget to unwrap them.

I also use the following function in my .vimrc so I'll not forget to
add the closing element:

" define XML/HTML tag creation function
" pass a second parameter to set the number of spaces
" for the indentation
function! Xmltag (tagname, ...)
    let tabx = ''
    if a:0 > 0
        let ix = 0
        while ix < a:1
            let tabx = tabx . " "
            let ix = ix + 1
        endwhile
    endif
    call append(line(".") + 0, tabx . "<" . a:tagname . ">")
    call append(line(".") + 1, tabx . " " . "CONTENT_HERE")
    call append(line(".") + 2, tabx . "</" . a:tagname . ">")
    /CONTENT_HERE
endfunction

" define the user command "Z" when editing XML/HTML/XSL
au BufNewFile,BufRead *.html,*.xml,*.xsl command! -nargs=+ Z call
Xmltag(<f-args>)

And just call the function using (for example):

:Z refentry 2

Cheers and happy vimming!

--- Jesus M. Castagnetto
-------------------------------------------------
Created by Zkey.com - http://www.zkey.com
Awarded PCMagazine's Editors' Choice