Is there some plugin to fold HTML tags in Vim?
Or there is another way to setup a shortcut to fold or unfold html tags?
I would like to fold/unfold html tags just like I do with indentation folding.
Open it in Vim, and place the cursor at the beginning of a paragraph. Make sure you're in normal mode, and type zf2j . After you press j , Vim will create a fold covering three lines — the line you started the fold on, and the next two lines.
The problem is that when you close Vim, your artfully folded code returns to its unfolded state. The solution is quite simple - when you are ready to save your folds run the :mkview command. This will save your folds in the current buffer to your viewdir ( :h viewdir ) depending on your environment.
I have found zfat
(or, equally, zfit
) works well for folding with HTML documents. za
will toggle (open or close) an existing fold. zR
opens all the folds in the current document, zM
effectively re-enables all existing folds marked in the document.
If you find yourself using folds extensively, you could make some handy keybindings for yourself in your .vimrc.
If you indent your HTML the following should work:
set foldmethod=indent
The problem with this, I find, is there are too many folds. To get around this I use zO
and zc
to open and close nested folds, respectively.
See help fold-indent
for more information:
The folds are automatically defined by the indent of the lines. The foldlevel is computed from the indent of the line, divided by the 'shiftwidth' (rounded down). A sequence of lines with the same or higher fold level form a fold, with the lines with a higher level forming a nested fold. The nesting of folds is limited with 'foldnestmax'. Some lines are ignored and get the fold level of the line above or below it, whichever is lower. These are empty or white lines and lines starting with a character in 'foldignore'. White space is skipped before checking for characters in 'foldignore'. For C use "#" to ignore preprocessor lines. When you want to ignore lines in another way, use the 'expr' method. The indent() function can be used in 'foldexpr' to get the indent of a line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With