vimtricks.wiki Concise Vim tricks, one at a time.

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 ftplugin or an autocmd for 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=marker must be enabled first; foldmarker only applies in that mode
  • Use setlocal foldmarker=... to limit the change to the current buffer
  • The fold level depth still uses the optional {{{N / }}}N suffix — e.g., #region{{{2 sets fold level 2
  • To view your current markers: :set foldmarker?

Next

How do I prevent Vim from adding a newline at the end of a file when saving?