Vim folding without end markers

I would like to add text between the starting markers, for example:

//// Block 1

... some code 1 ...

//// Block 2

... some code 2 ...

where it ////will be used as an initial marker, and folding //// Block 1will add up to the line before //// Block 2.

Is it possible?

I don’t like it if I install foldmarkerwithout a final parameter, and it bends too much if I use ////the start and end markers as a marker.

I could manually create folds with zf, but they depend on the file and are interrupted if you change it.

+4
source share
1 answer

You can write your own expression in the form:

function! BlockFolds()
   let thisline = getline(v:lnum)
   if match(thisline, '^\/\/\/\/ Block') >= 0
      return ">1"
   else
      return "="
   endif
endfunction

setlocal foldmethod=expr
setlocal foldexpr=BlockFolds()

If you send it to vim, you will get the desired effect:

demo

, .vimrc . , fold: http://vimcasts.org/episodes/writing-a-custom-fold-expression/

+3

Source: https://habr.com/ru/post/1620905/


All Articles