tags:

views:

90

answers:

1
+2  A: 

Do you want to edit the first line of the folded block, or the string that appears when the fold is closed? If it's the former, I don't think you can do it without opening the fold. If it's the latter, then have a look at the foldtext option. It can be any expression. This expression is evaluated to create this string.

From the docs:

'foldtext' is a string option that specifies an expression. This expression is evaluated to obtain the text displayed for a closed fold. Example:

:set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')

This shows the first line of the fold, with "/", "/" and "{{{" removed. Note the use of backslashes to avoid some characters to be interpreted by the ":set" command. It's simpler to define a function and call that:

:set foldtext=MyFoldText()
:function MyFoldText()
:  let line = getline(v:foldstart)
:  let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
:  return v:folddashes . sub
:endfunction

An alternative is using the marker folding method. With it, you can enter any string before the fold marker and it will appear when the fold is closed.

From the docs:

Markers in the text tell where folds start and end. This allows you to precisely specify the folds. This will allow deleting and putting a fold, without the risk of including the wrong lines. The 'foldtext' option is normally set such that the text before the marker shows up in the folded line. This makes it possible to give a name to the fold.

Markers can have a level included, or can use matching pairs. Including a level is easier, you don't have to add end markers and avoid problems with non-matching marker pairs. Example:

/* global variables {{{1 */
int varA, varB;
Ayman Hourieh
so the answer is that you cannot edit characters in the heading without opening the fold.
Masi