diff --git a/README.adoc b/README.adoc index 7513418..aa60472 100644 --- a/README.adoc +++ b/README.adoc @@ -11,6 +11,17 @@ In addition to making reading AsciiDoc documents much easier, syntax highlightin This repository contains the Vim files necessary to syntax highlight AsciiDoc in Vim. A stable version of these files is included in the Vim distribution (see https://github.com/vim/vim/blob/master/runtime/syntax/asciidoc.vim[]). +== Folding + +Folding on the section level is included as well. +To enable the folding, add + +---- +let g:asciidoc_folding=1 +---- + +to the `.vimrc` file. + == Installation (development files) Install the highlighter by copying `asciidoc.vim` to your `$HOME/.vim/syntax` directory. diff --git a/ftplugin/asciidoc.vim b/ftplugin/asciidoc.vim new file mode 100644 index 0000000..e3ba082 --- /dev/null +++ b/ftplugin/asciidoc.vim @@ -0,0 +1,44 @@ +function! AsciidocFold() + let line = getline(v:lnum) + if (line =~ '\v^[a-zA-Z]') + let nextline = getline(v:lnum + 1) + if (strlen(nextline) != strlen(line)) + return "=" + elseif (nextline =~ '\v^\=+$') + return ">0" + elseif (nextline =~ '\v^-+$') + return ">1" + elseif (nextline =~ '\v^\~+$') + return ">2" + elseif (nextline =~ '\v^\^+$') + return ">3" + elseif (nextline =~ '\v^\++$') + return ">4" + endif + elseif (line =~ '\v^\=') + if (line =~ '\v^\=\s') + return ">0" + elseif (line =~ '\v^\=\=\s') + return ">1" + elseif (line =~ '\v^\=\=\=\s') + return ">2" + elseif (line =~ '\v^\=\=\=\s') + return ">3" + elseif (line =~ '\v^\=\=\=\=\s') + return ">4" + endif + elseif (line =~ '\v^----$') + let prevline = getline(v:lnum - 1) + if (prevline[0] == "[") + return "a1" + else + return "s1" + endif + endif + return "=" +endfunction + +if has("folding") && exists("g:asciidoc_folding") + setlocal foldexpr=AsciidocFold() + setlocal foldmethod=expr +endif