Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foldmethod=marker and syntax at the same time?

Tags:

vim

Is it possible for a same file to use folding based on both markers and syntax ?

like image 726
Running Turtle Avatar asked Apr 22 '11 15:04

Running Turtle


3 Answers

Since foldmethod can only be set to one at a time, I think the only way you could really do this would be to use :set foldmethod=expr and hack about with foldexpr, and even then I'm not sure it would be able to do exactly what you want.

So, short answer: no

Long answer: maybe, muck about with foldexpr if you dare to see if you can get the desired results

like image 168
Daniel DiPaolo Avatar answered Nov 17 '22 21:11

Daniel DiPaolo


Maybe you can emulate your markers by additional syntax rules?

But hard to tell without more input.

like image 20
osti Avatar answered Nov 17 '22 20:11

osti


The AutoFold.vim plugin attempts to address this: http://www.vim.org/scripts/script.php?script_id=925

As an alternative, I thought I'd have a little go myself, by introducing a new syntax rule for markers. Unfortunately this needs to be declared before any syntax rules for comments, or the comment rule will mask our marker rule.

So here is what I tried to insert my rule early:

:syn clear

:syn region myMarkerFold matchgroup=myDummyGroup start="{{{" end ="}}}" transparent fold

:exec "runtime! syntax/" . &filetype . ".vim"    

It didn't quite work. The last line immediately cleared my custom rule. Drop the last line, and folding works, but of course none of the language will be syntax-matched or highlighted! (By the way, I was testing this on a .vim file.)

like image 1
joeytwiddle Avatar answered Nov 17 '22 21:11

joeytwiddle