Vim Markdown Folding?

2019-01-17 03:41发布

I just realized that VIM 7.3 has built-in support for highlighting Markdown files. Excellent. However, it doesn't fold on the headings.

Can any offer suggestions on how to get this working?


Alternatively, I'm using Markdown only as a way to get simple structured text. If there is a better alternative format, please also suggest. But not sure I dig TVO or VimOutliner.

标签: vim markdown
11条回答
仙女界的扛把子
2楼-- · 2019-01-17 04:13

I'm guessing you don't watch VimCasts. The guy who makes that made a pugin for just this. Here it is: https://github.com/nelstrom/vim-markdown-folding

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-17 04:13

Based on Jeromy & Omar's suggestions, I came up with this (for my vimrc) to automatically and unambiguously fold my DokuWiki files (in which top level header is marked by ====== at start of line, down to fourth level header marked by ===):

function! DWTitleLevel()
    let j = len(matchstr(getline(v:lnum), '^=\+'))
    if     j =~ 6 | return ">1"
    elseif j =~ 5 | return ">2"
    elseif j =~ 4 | return ">3"
    elseif j =~ 3 | return ">4"
    endif
endfunction

'^=+' means match from the start of the line any number of contiguous '='s

Then this in a vim modeline makes it work nicely for a DokuWiki file:

foldmethod=expr foldexpr=DWTitleLevel() foldcolumn=5

And for Markdown, I needed to write Omar's code like this:

if empty(j) | return "=" | else | return ">".len(j) | endif
查看更多
地球回转人心会变
4楼-- · 2019-01-17 04:15

VOoM : Vim two-pane outliner is worth checking it out.

Not only does it provide basic folding, but it also provides outline navigation via a 2nd outline view pane (similar to document map in MS Word). And it supports a large number of markup languages including others mentioned in other answers - Markdown, viki, reStructuredText, vimwiki, org, and many others.

For more info see the screenshots and the help page.

查看更多
Deceive 欺骗
5楼-- · 2019-01-17 04:16

There is an app a plugin for that on GitHub.

vim-markdown-folding

When you are editing Markdown files with Vim, you probably also want to install Tim Pope's Markdown plugin.

vim-markdown

查看更多
闹够了就滚
6楼-- · 2019-01-17 04:19

The only way how I get folding to work in markdown, was't very elegant, :set fdm=marker and use html comment tag

 <!-- My folding {{{1 -->

more help :help folding

查看更多
登录 后发表回答