Question

I see a few posts saying I should use zfat to fold html tags. So i tried it but did not get the results I expected. For example, I had this in my document

<div id="begin">
   <p>hello world</p>
      </div>

I moved my cursor in vim to the first line of <div id="begin">. Then I pressed escape to make sure I'm in command mode. Then I pressed the keys z, f, a and t. But nothing happened. I even tried typing z, f, a and {, which normally folds blocks of PHP code, but it has no effect on the html.

Can some one tell me the exact steps to fold the html div tags?

Thanks

Was it helpful?

Solution

zf indeed is the command to create a manual fold. For that to work, you need to have

:setlocal foldmethod=manual

(There will be an E350 otherwise.) The at is a text object for a tag. You can check what it comprises by applying it to visual mode instead: vat.

Note that manual folding is tedious; I'd recommend to use the syntax folding that comes with the built-in HTML syntax plugin. Just put

:setlocal foldmethod=syntax

in ~/.vim/after/ftplugin/html.vim to enable it.

Also note that so far (as of Vim 7.4.1830), the default HTML syntax script only folds a multi-line tag itself, not the text between the opening and closing tag. To achieve that, you need a syntax extension, see here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top