Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining vim's fold and conceal feature

Tags:

vim

I'm using vim's conceal feature to display my latex files in a somewhat more readable form.

Furthermore, I'm using the vim-latex plugin, which creates folds for the math environments which then show the label and the beginning of the content of the environment.

Example: The math environment in plain latex code looks like this:

\begin{align}
   \xi = \cos \alpha
   \label{eqn:test}
\end{align}

Using the vim's conceal feature, it is displayed as

\begin{align}
   ξ = \cos α
   \label{eqn:test}
\end{align}

When vim now creates the fold, it displays as

+--  4 lines: align (eqn:test): \xi = \cos \alpha

My question is now: Is it possible to get vim to apply the conceal to the description of the folds, so that it looks like below?

+--  4 lines: align (eqn:test): ξ = \cos α
like image 562
Simon L. Avatar asked Aug 16 '13 14:08

Simon L.


1 Answers

In general, the foldtext and conceal could be combined. But this needs to be implemented by yourself, following the conceal logic.

The option foldtext defines the text to display, when a fold was closed. The value of the option could be a vim function or expression. so we could do pretty much modification on the original text.

Conceal. usually it does: when X pattern matched, display Y instead of X. So we could write a function, read the foldstart line, check the conceal syntax patterns, if the line matches any, if True, then remove those matched part, and display the cchar. We set this function as value of foldtext option. Of course only for certain file type.

For highlighting, these two groups could be used for foldtext.

Folded      line used for closed folds
FoldColumn  'foldcolumn'

It is what I can think of. If someone could have some better/easier way to do it, I am glad to learn. for example some build-in function, which I don't know, could help in this situation.

like image 82
Kent Avatar answered Oct 13 '22 14:10

Kent