I mostly want it to automatically create folds for between a begin and an end, although if there's anything more advanced that would be welcome too.I've looked in the help for the pascal syntax and it doesn't support syntax folding.
How to create syntax folding for pascal
syntax highlighting;folding
The following seems to patch syntax folding onto the Pascal syntax that ships with Vim. Put this into ~/.vim/after/syntax/pascal.vim:syn clear pascalLabel pascalStatement pascalStructsyn keyword pascalLabel     goto labelsyn keyword pascalStatement procedure functionsyn keyword pascalStatement program const var typeif !exists(pascal_traditional)  syn keyword pascalStatement   constructor destructor implementation inherited  syn keyword pascalStatement   unit uses  syntax region pascalInterface matchgroup=pascalStatement start=\<interface\> end=\<end\> transparent fold  syntax region pascalObject matchgroup=pascalStruct start=\<object\> end=\<end\> transparent foldendifsyn keyword pascalRecordCaseLabel case contained containedin=pascalRecordsyntax region pascalBlock matchgroup=pascalStatement start=\<begin\> end=\<end\> transparent foldsyntax region pascalCase matchgroup=pascalLabel start=\<case\> end=\<end\> transparent foldsyntax region pascalRecord matchgroup=pascalStruct start=\<record\> end=\<end\> transparent fold contains=TOP,pascalCasehighlight def link pascalRecordCaseLabel pascalLabelsetlocal foldmethod=syntaxI had to :syn-clear some existing definitions. It would be better if the author of the syntax plugin included this into the main script. Also note that I'm not too familiar with Pascal syntax, and hacked this together quickly. No warranties :-)