VIM: folding bullet points

vivimvimrc

I'm quite new to VIM, but have been trying to teach myself over the past week, yet I'm encountering a problem which has proven to be quite frustrating:

Currently I'm mostly using VIM to take notes, and use the folding capabilty of VIM to make my work less cluttered. Yet I've encountered a problem, where every bullet point, which goes beyond my set linebreak, folds in itself. To be more clear:

VIM I
enter image description here

I would like to not have single bullet points fold.

I seem to have traced the problem to the way my text is indented: since folding seems to happen on an indent-level by default, my bullet points fold due to the second line being 'indented' more. So I gather there are probably to vague ways of solving this issue: telling VIM to fold if the indent on the next line is greater 1, or handle the way bullet points are wrapped completely differently.

How can these solutions be implemented?


I use a plugin called Workflowish, so here is my vimrc:

set tw=100
set formatoptions=tcq
set com=fb:*
set spell
set spelllang=de
colorscheme synic
set fileencoding=utf8
execute pathogen#infect()
syntax on
filetype plugin indent on

And here is what the plugin itsself sets:

setlocal foldlevel=1
setlocal foldenable
setlocal sw=2 sts=2
setlocal expandtab
setlocal foldtext=WorkflowishFoldText()
setlocal foldmethod=expr
setlocal foldexpr=WorkflowishCompactFoldLevel(v:lnum)
setlocal autoindent

Best Answer

Unfortunately, there's no way to do this without support from the plugin. (Sort of.)

The key lines here are:

setlocal foldmethod=expr
setlocal foldexpr=WorkflowishCompactFoldLevel(v:lnum)

The first means "use the value of 'foldexpr' to determine the fold level of each line". The second sets that option to use the value of a function defined in the plugin.

Folding in Vim is based on fold levels. In foldmethod=expr, each line is assigned a fold level (an integer) by the 'foldexpr'. Those levels determine where the folds begin and end.


Solution 1: Write a new 'foldexpr'.

This can call WorkflowishCompactFoldLevel(), but adjust the value so that multi-line bullet-items aren't folded. I'll leave this as an exercise, though, because I think it's the wrong approach. Which brings us to:


Solution 2: Make the way it works now not be a problem.

I think the real problem is not that these folds exist, but that they're getting in your way. Can you describe what you do that causes you to even notice that these folds are there? It may be a matter of setting your starting 'foldlevel' appropriately for ft=workflowish buffers.

Ideally, you wouldn't notice that these folds existed until you actually tried to close one.

Related Question