Monday, November 29, 2010

Re: major confusion on vim folding behavior I'm seeing

On Mon, 29 Nov 2010, Rick R wrote:

> On Mon, Nov 29, 2010 at 3:21 AM, Benjamin R. Haskell wrote:
>
>> But, in order to do syntax-based folding, the syntax needs to be set
>> up in the more-complicated, "region"-based way. The XML highlighting
>> is a great example of a well-written syntax that uses this method,
>> IMO.
>>
>> HTML mainly uses regions to provide the text formatting tricks that
>> it adds (underlined <a> text, bolded <b> text, etc.). My guess is
>> that the main reason it doesn't work the same way the XML syntax does
>> is that HTML, as an SGML application, doesn't require matched closing
>> tags (so writing a grammar for it in terms of syntax regions can be
>> quite complicated).
>>
>
> I'll keep trying to figure it out or maybe I'll just stick to
> KomodoEdit with the vim mode enabled. I have some large html files I
> have to deal with and having folding comes in handy.
>
> I thought about trying this
> http://www.vim.org/scripts/script.php?script_id=1397 but I didn't
> understand these instructions:
>
> "when you have filetype indent on. Then create a ~/.vim/indent directory and
> for every link (copy) you made do
> echo "let b:did_indent = 1" > ~/.vim/indent/xml.vim"

That plugin can apparently handle the filetypes:
xml, docbk, xsl, html, and xhtml

But, since the built-in filetype plugins for those filetypes each set up
their own indent-handling, you need to override it by claiming that it's
already done.

So, if you want to handle xml, docbk, and html, you need to:

( -- directions from your link -- )
1. copy that plugin's xml.vim file to your own ~/.vim/ftplugin/xml.vim

2. Link (or copy, under Windows) to ~/.vim/ftplugin/docbk.vim and html.vim

( -- then the part that you asked about above -- )
3. For everything in #2 (docbk and html in my example), override the
indent handling:

for type in docbk html ; do
echo "let b:did_indent = 1" > ~/.vim/indent/${type}.vim
done

Assuming you're on non-Windows, I'd probably actually handle both things
the same way:

cp xml.vim ~/.vim/ftplugin/
echo "let b:did_indent = 1" > ~/.vim/indent/xml.vim
for type in docbk html ; do
ln -s xml.vim ~/.vim/ftplugin/${type}.vim
ln -s xml.vim ~/.vim/indent/${type}.vim
done

--
Best,
Ben

--
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

No comments:

Post a Comment