Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In vim I would like to change the folding behavior. Suppose I fold this block:

=== fileName ===

        == summary ==

                I think that this defines the class to use for the authentication
                and the parameters to pass the class.

        == tags ==

                <bla bla>
                </bla bla>

It becomes:

=== fileName ===

        == summary ==

+---  2 lines: I think that this defines the class to use for the authentication------------

        == tags ==

                <bla bla>
                </bla bla>

I think that it would be easier to read if it became:

=== fileName ===

        == summary ==

                +---  2 lines: I think that this defines the class to use for the authentication------------

        == tags ==

                <bla bla>
                </bla bla>

(The desired result has an extra tab)

FYI: I have this in my vimrc:

"use indents as the folding method
set foldmethod=indent

"make vim save and load the folding of the document each time it loads
au BufWinLeave * mkview
au BufWinEnter * silent loadview

Update

Upon recommendation from njd I tried setting the foldtext to my own function. I tried both the one that he suggested and the one below. However neither had any effect.

function! MyFoldText()
  return 'johnny'
endfunction

set foldtext=MyFoldText()

What am I missing here?

Note: I also have this: set foldmethod=indent in my .vimrc.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

So you want to have the fold message line up with the indent of the folded text?

You need to set the 'foldtext' option to something other than the default foldtext() function.

Something like this:

function! MyFoldText()
  let lines = 1 + v:foldend - v:foldstart
  let spaces = repeat(' ', indent(v:foldstart))

  let linestxt = 'lines'
  if lines == 1
    linestxt = 'line'
  endif

  let firstline = getline(v:foldstart)
  let line = firstline[ind : ind+80]

  return spaces . '+' . v:folddashes . ' ' . lines . ' ' . linestxt . ': ' . line . ' '
endfunction

Then

:set foldtext=MyFoldText()
share|improve this answer
    
Wow is there really not an easier answer? –  sixtyfootersdude Feb 24 '10 at 14:45
1  
Easier like ":set foldmessageplacement=indent" ? No. No such option exists. Just paste that function into your .vimrc, and add the :set command, and you're done. Easy. –  njd Feb 24 '10 at 15:06
    
Hey, thanks for the feedback. Put that code into my .vimrc but it had no effect. I modified the function to this: function! MyFoldText() return 'hello world' endfunction set foldtext=MyFoldText() But this also had no effect on the folding. Can you offer some clarification as to why this may be having no effect? –  sixtyfootersdude Feb 25 '10 at 15:14
1  
My mistake - that "return ..." line should have the correct string concatenator (.) before v:folddashes instead of +. I've corrected my answer. You won't see the change until you reopen and then close a fold. –  njd Feb 25 '10 at 23:43
1  
I also found that this line: let line = firstline[ind : ind+80] did not work so I changed it for let line = firstline –  sixtyfootersdude Mar 9 '10 at 22:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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