
-- >8 --
我有一個用作部分分隔符號的純文字文件,例如:
-- >8 --
first section
some content
more content
-- >8 --
second section
some content
more content
-- >8 --
為了更輕鬆地導航文件,我想折疊標記之間的部分。我原以為會很簡單:
set foldmethod=marker
set foldmarker=--\ >8\ --,--\ >8\ --
但這會導致嵌套折疊。
我發現我可以使用折疊表達式來實現此目的(請參閱下面的答案),但它似乎相當過分。有更簡單的方法嗎?
答案1
我發現我可以使用折疊表達式來執行此操作:
set foldmethod=expr
set foldexpr=(getline(v:lnum)=='--\ >8\ --')?1:2
螢幕截圖:
- -- >8 --
|++--- 5 lines: first section------------------------------------------------
| -- >8 --
|++--- 5 lines: second section-----------------------------------------------
| -- >8 --