2

If my file already has

{{{
  fold contents here
  ...
}}}

blocks I want them to be automatically folded when I run za; but I want the ability to create a manual fold using zf%, say on just

{

  fold contents here
  ....

} 

without vim automatically modifying my file to

{/*{{{*/

fold contents here
...

}/*}}}*/

I thought that

:help fold-create-marker

might be relevant, but I do not understand it.

I have a workaround, but would like a cleaner solution.

.vimrc workaround:

map <Leader>Zf :set fdm=marker<CR>za:set fdm=manual<CR>za|"create marker method fold, but return to manual fold method
" Above intended for case where '{{{' preexists on currentline, and matching '}}}' exists on subsequent line
1
  • Default behavior: add 'foldmarker' surrounded by 'commentstring' :he foldmarker -> string (default: "{{{,}}}") :he commentstring -> string (default "/*%s*/") 'commentstring' is used if it isn't empty.
    – Alex Kroll
    May 19, 2015 at 10:29

1 Answer 1

3

You could do a global match on all fold markers to create manual folds.

:g/{{{/normal! $Nzf%

This assumes that {} braces are balanced inside the fold markers, but if you use the "matchit" plugin distributed with Vim, you can make this better with:

:let b:match_words = '{{{:}}}'

It also assumes that there's only one opening fold marker per line, but I don't see a good way to remove that assumption short of custom scripting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.