Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indenting fold text

Tags:

vim

folding

When you unfold nested levels of your code the folded text in nested code is not indented. It begins on the beginning of the line with + instead of starting indented.

Do you know how to change it?

illustrating picture

like image 564
xralf Avatar asked Dec 18 '25 16:12

xralf


2 Answers

If you want the fold text to be indented at the same level as the first line of the fold, you need to prepend the indent level to the foldtext:

function! MyFoldText()
    let indent_level = indent(v:foldstart)
    let indent = repeat(' ',indent_level)
    ...
    ...   
    return indent . txt
endfunction

Here I am assuming that the string txt is your existing foldtext, so all you need to do is add it to the end of indent.

But I am not sure if that is what you want to achieve.

EDIT:

Now I have seen your picture, I'm not sure if this is what you want. You could try stripping the leading whitespace before appending to the +. So the foldtext you want will be something like indent . '+' . txt.

Maybe.

like image 108
Prince Goulash Avatar answered Dec 20 '25 11:12

Prince Goulash


Aha

You might want to comment out this function in your .vimrc:

set foldtext=MyFoldText()
set fillchars=fold:_

This is what makes your fold text appearing non default, by using the function:

function! MyFoldText()
  " setting fold text
  let nl = v:foldend - v:foldstart + 1
  let comment = substitute(getline(v:foldstart),"^ *\" *","",1)
  let linetext = substitute(getline(v:foldstart+1),"^ *","",1)
  let txt = '+ ' . comment . ': ' . nl .  ' ' . v:foldstart . '                                                                                                                                                                  '
  return txt
endfunction

As it happens, I quite like that function, but of course, de gustibus...

like image 40
sehe Avatar answered Dec 20 '25 11:12

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!