Friday, November 14, 2014

Re: Fold first paragraph, including its children based on indent

On 11/13/14, fpxo13@gmail.com <fpxo13@gmail.com> wrote:
> For note-taking I use vim.
>
> I would like to keep a convenient overview of my notes with folding.
>
> Therefor I'm using the fold method "indent".
>
> However, this method doesn't cover all my needs.
>
> I would like to be able to fold all indent levels, including the first
> paragraph.
>
> Unfortunately, it is not possible to fold the first paragraph, see
> screenshot http://i.imgur.com/1N9bY3b.png .
>
> I would love to this made possible.
>
> I hope someone can help me with this.
>

The following fold settings will do it:

"---------------------------------------------------------------------
setl foldmethod=expr
setl foldexpr=FoldexprIndentedOutline(v:lnum)
func! FoldexprIndentedOutline(lnum)
let lev = indent(a:lnum) / &sw + 1
let levn = indent(a:lnum+1) / &sw + 1
return levn>lev ? '>'.lev : lev-1
endfunc
setl foldtext=FoldtextIndentedOutline()
func! FoldtextIndentedOutline()
return substitute(getline(v:foldstart), '\t', repeat(' ',&sw), 'g')
endfunc
"---------------------------------------------------------------------

The substitute() in 'foldtext' is needed when indenting is done with
tabs. Otherwise it can be simply
:setl fdt=getline(v:foldstart)

To also display level and/or the number of hidden lines, append
something like the following to the foldtext string:
.' /'.v:foldlevel.'...'.(v:foldend-v:foldstart)

Various outlining-related plugins are listed here:
http://vim.wikia.com/wiki/Script:List_of_scripts_for_outlining

Regards,
Vlad

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment