Question

I'm trying to customize vim folding style and stuck with indentation. I know it has been asked multiple times here and I use this command (which seem to work for others) to test the appearance of fold:

:set foldtext=' '.foldtext()

This however gives me 'unknown option' error. Apparently, it doesn't accept the string containing only space(s), because this

:set foldtext='mytext'.foldtext()

works fine and adds 'mytext' to the beginning of folds.

Why doesn't it work and what's the way around it?

Was it helpful?

Solution

You just need to escape the space. Use this instead.

:set foldtext='\ '.foldtext()

The space is causing vim to think you want to set foldtext to ' and then '.foldtext() is the next argument to set. However this isn't what you want and the reason the error message is

E518: Unknown option: '.foldtext()

Escaping the space tell vim that foldtext='\ '.foldtext() is one argument instead of two.

OTHER TIPS

You can use the EightHeader plugin if you prefer aligned foldtext. Example from the help:

If you don't like the default 'foldtext' you can customize it by setting to EightHeaderFolds().

For example the closed folds looks like this by default:

```+-- 45 lines: Fold level one
+--- 67 lines: Fold level two

If you would like to change it to this kind:

Fold level one................45 lines
  Fold level two..............67 lines

... then you can use this function:

let &foldtext = "EightHeaderFolds( '\\=s:fullwidth-2', 'left', [ repeat( '  ', v:foldlevel - 1 ), '.', '' ], '\\= s:foldlines . \" lines\"', '' )"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top