問題描述

有沒有一些插件可以在 Vim 中摺疊 HTML 標籤?還有另一種方法來設置摺疊或展開 html 標籤的快捷方式?我想像摺疊摺疊一樣摺疊/展開 html 標籤。

最佳解決方法

我發現 zfat(或同樣地,zfit) 適用於 HTML 文檔的摺疊。 za 將切換 (打開或關閉) 現有的摺疊。 zR 打開當前文檔中的所有摺疊,zM 有效地將 re-enables 中的所有現有摺痕標記在文檔中。

如果您發現自己使用褶皺廣泛,您可以為您自己的.vimrc. 中的一些方便的按鍵綁定

次佳解決方法

如果縮進您的 HTML,以下內容應該有效:

set foldmethod=indent

這個問題,我發現,有太多的摺疊。為瞭解決這個問題,我使用 zOzc 分別打開和關閉嵌套摺疊。

有關詳細信息,請參閲 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.

第三種解決方法

安裝 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 orignal html:

js-beautify 和 vim 摺疊:

第四種方法

再加上詹姆斯·賴的回答。最初我的 foldmethod =語法,所以 zfat 將無法工作。解決辦法是將摺疊方法設置為手動

:setlocal foldmethod=manual

檢查使用哪種摺疊方法,

:setlocal foldmethod?

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇