html折叠标记,如何使用Vim折叠/展开HTML标签

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

是否有一些插件可以在Vim中折叠HTML标签?

还是有另一种方法来设置折叠或展开html标签的快捷方式?

我想像缩进折叠一样折叠/展开html标签。

nsbm asked 2019-11-10T07:53:22Z

6个解决方案

76 votes

我发现.vimrc.(或相等地zfit)可以很好地折叠HTML文档。 za将切换(打开或关闭)现有折页。 zR打开当前文档中的所有折叠,zM有效地重新启用文档中标记的所有现有折叠。

如果发现自己广泛使用折叠,则可以在.vimrc.中为自己做一些方便的键盘绑定

James Lai answered 2019-11-10T07:53:52Z

18 votes

如果您缩进HTML,则下面的方法应该起作用:

set foldmethod=indent

我发现与此有关的问题是折叠太多。 为了解决这个问题,我分别使用help fold-indent和zc打开和关闭嵌套折叠。

有关更多信息,请参见help fold-indent:

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.

ihohbeto answered 2019-11-10T07:54:35Z

5 votes

使用foldmethod语法折叠html,这比较简单。

这个答案是基于vim中的HTML语法折叠。 作者是@Ingo Karcat。

使用以下命令将fold方法设置为语法:

vim命令行syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d

或将设置输入syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d

syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d

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

syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d

要在标签之间折叠,您需要通过以下方式扩展语法脚本:以下,进入syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d的最佳位置

语法折叠在所有无效的html元素之间执行(没有亲密兄弟姐妹的人,例如syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d)

syntax region htmlFold start="\)\@![a-z-]\+\>\)\%(\_s*\_[^/]\?>\|\_s\_[^>]*\_[^>/]>\)" end="\z1\_s*>" fold transparent keepend extend containedin=htmlHead,htmlH\d

soarinblue answered 2019-11-10T07:56:04Z

3 votes

安装js-beautify命令(JavaScript版本)

npm -g install js-beautify

wget --no-check-certificate https://www.google.com.hk/ -O google.index.html

js-beautify -f google.index.html -o google.index.bt.html

[http://www.google.com.hk]原始html:

ae7e7b2e3273d1e6aa4a8af60ff376fd.png

js-beautify和vim折叠:

2SgKF.png

kainan answered 2019-11-10T07:56:44Z

2 votes

加上詹姆斯·赖的回答。最初,我的foldmethod = syntax,所以zfat无法使用。解决方法是将折页方法设置为手动

:setlocal foldmethod=manual

检查使用哪种折纸方法,

:setlocal foldmethod?

ken answered 2019-11-10T07:57:20Z

1 votes

首先是set foldmethod=syntax,然后尝试zfit折叠开始标签,并尝试2607765814505899099010展开标签,这在我的vim上效果很好。

Ryan Chou answered 2019-11-10T07:57:48Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值