How do I change the default {{{ and }}} fold markers to custom delimiter strings?
Answer
set foldmarker=start,end
Explanation
When using foldmethod=marker, Vim uses {{{ and }}} as the default fold open and close markers. The foldmarker option lets you replace these with any strings that suit your file format or team convention.
How it works
set foldmarker=start,end— defines two comma-separated strings: the fold opener and closer- Vim scans for these strings in the text to determine fold boundaries
- Marker strings can contain any characters — they don't need to be unique to the fold system
- Set this in
ftpluginor anautocmdfor per-filetype marker styles
Example
For HTML files, use HTML comments as fold markers:
autocmd FileType html setlocal foldmethod=marker foldmarker=<!--,-->
For editors that use VS Code–style region comments:
set foldmarker=#region,#endregion
Your code can then include:
#region Auth
...
#endregion
Tips
set foldmethod=markermust be enabled first;foldmarkeronly applies in that mode- Use
setlocal foldmarker=...to limit the change to the current buffer - The fold level depth still uses the optional
{{{N/}}}Nsuffix — e.g.,#region{{{2sets fold level 2 - To view your current markers:
:set foldmarker?