6

When I create a fold with zfap, vim displays something like:

+--  15 lines: myFunctionPrototype :: Test -> Test -> Bool 

However, I would like vim not to display this number of lines. I find this distracting, and not adding sufficient information in my case.

I'd prefer:

+-- : myFunctionPrototype :: Test -> Test -> Bool

or even better:

+-- myFunctionPrototype :: Test -> Test -> Bool

Is there a way to suppress the line count, or a way to modify what vim displays when there's a fold that I could put in my vimrc ?

2 Answers 2

3

to put in .vimrc:

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

MyFoldText is now the function that is responsible for displaying some text, when some lines have been folded.

6
  • '/\*\|\*/\|{{{\d\=' .... er, excuse me? I didn't quite catch that. The line is terrible. I think you must be speaking over VOIP.
    – markling
    Commented Oct 24, 2022 at 9:20
  • Thank you for the comment, it made me laugh. Well, let's try to filter out noise on your phone line. Commented Dec 26, 2022 at 18:19
  • First, some characters has to be escaped, as you probably know it from other languages than VIMScript, which I plan to learn soon, but I have pushback that idea until the last possible moment :-) Commented Dec 26, 2022 at 18:21
  • "/*" is short for the C++ begin comment /* the start is * ; and similarily "*/" is for end comment Commented Dec 26, 2022 at 18:22
  • "{{{" is used by vim as a marker so as to fold text Commented Dec 26, 2022 at 18:26
2

The text that is displayed for a closed fold is determined by the 'foldtext' option. See

:help 'foldtext'
:help fold-foldtext

The latter topic has a few examples of ways to get different text. As another, simple example,

:set foldtext=v:folddashes

will result in a line of only dashes (actually hyphens) across the full width of the window.

2
  • not accros the full width of the window. I only have one dash at the start. but thanks, that's where I have to look at. Commented Sep 5, 2015 at 18:25
  • Yes, across the full width of the window. Example: vim -N -u NONE -c "set foldtext=v:folddashes" -c "put=''" -c "normal ggzfG"
    – garyjohn
    Commented Sep 6, 2015 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.