首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Vim折叠/展开HTML标签

问如何使用Vim折叠/展开HTML标签
EN

Stack Overflow用户
提问于 2011-08-22 21:33:52
回答 6查看 25.9K关注 0票数 68

Vim中有没有用来折叠HTML标签的插件?

或者有另一种方法可以设置快捷方式来折叠或展开html标签?

我想要折叠/展开html标签,就像我使用缩进折叠一样。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2012-09-12 10:55:58

我发现zfat (或者,同样的,zfit)可以很好地折叠HTML文档。za将切换(打开或关闭)现有的文件夹。zR打开当前文档中的所有折叠,zM有效地重新启用文档中标记的所有现有折叠。

如果您发现自己经常使用folds,那么可以在.vimrc.中为自己做一些方便的键绑定

票数 93
EN

Stack Overflow用户

发布于 2013-06-30 05:20:34

如果您缩进您的HTML,以下内容应该可以工作:

代码语言:javascript
复制
set foldmethod=indent

我发现这样做的问题是有太多的折叠。为了解决这个问题,我使用zO和zc分别打开和关闭嵌套的folds。

有关详细信息,请参阅help fold-indent:

代码语言:javascript
复制
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.
票数 25
EN

Stack Overflow用户

发布于 2016-07-09 13:51:20

用foldmethod语法折叠html,更简单。

这个答案是基于HTML syntax folding in vim的。作者是@Ingo Karcat。

  1. 将您的折叠方法设置为语法,如下所示:

vim命令行:set foldmethod=syntax

或者将设置放在~/.vim/after/ftplugin/html.vim中

setlocal foldmethod=syntax

  • Also注意,到目前为止,默认的语法脚本只折叠多行标记本身,而不是开始标记和结束标记之间的文本。

所以,这是折叠的:,这不是在这里和

  • 之间的文本,要在标记之间折叠,你需要扩展语法脚本,通过下面的最佳位置进入~/.vim/after/syntax/html.vim

语法折叠是在除了void html元素之外的所有元素之间执行的(那些没有接近兄弟的元素,比如<br>)

语法区域start="<\z(\<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|para|source|track|wbr>)\@+>)\%(\s*\^/\?>|\s\^>*\_^>/>)“end="”fold transparent keepend extend containedin=htmlHead,htmlH\d

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7148270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档