How do I define custom fold marker strings instead of the default {{{ }}} in Vim?
Answer
:set foldmarker=region,endregion
Explanation
When using foldmethod=marker, Vim looks for the strings in foldmarker to identify fold boundaries. The default is {{{,}}} — but these conflict with CSS, shell arithmetic, and other contexts. You can set any pair of distinct strings as your fold markers using :set foldmarker=START,END.
How it works
:set foldmethod=marker— enables marker-based folding:set foldmarker=START,END— sets the open and close marker strings- A number appended to a marker sets the fold level:
region1,region2etc. :setlocal foldmarker=...applies the setting to the current buffer only
Example
For Python files, use region/endregion markers that match IDE conventions:
:setlocal foldmethod=marker
:setlocal foldmarker=region,endregion
Now you can write:
# region <--- opens fold
def helper():
pass
# endregion <--- closes fold
For HTML files, use comments:
:setlocal foldmarker=<!--fold,fold-->
Tips
- Put
:setlocal foldmethod=marker | setlocal foldmarker=region,endregionin anautocmd FileType pythonblock in your vimrc to apply automatically - You can embed the open marker with a level digit to create nested folds:
# region1,# region2 - To hide the markers, pair with
:set conceallevel=2and aconcealsyntax rule :set foldmarker?shows the current value;:set foldmarker&resets to the default{{{,}}}