Fold Code Blocks

Use case or problem

In many cases, code blocks in notes are examples or logs. You can skim through the notes more efficiently with these code blocks folded.

Proposed solution

Make code blocks able to fold and unfold, just like in VS Code.


This seems so obvious. I need this. I’ve tried by using headers at the top of code block, which allows you to fold everything beneath it with it. You need a fold setting enabled. The issue is that it folds everything until the next heading it seems… I just need the code block folded. I can put specific headings at the bottom to stop it but that’s a pain.

Any suggestions are appreciated


Maybe you can try the callouts function


hope that helps

Creative idea!
Unfortunately it would mean every line in the codeblock needs to be prepended with the blockquote symbol, which adds another step to remove it when copy-pasting from the note.
More folding options built-in, without requiring community plugin, would be great!


If you setup autotext with the h6 followed by codeblock syntax, followed by h6 blank, then you only need write the title of the block after the first h6 and the code.

1 Like

This works. Thank you.
I’m using the Text Snippets plugin which I’m not sure if you were referring to.
With this snippet:
code : ###### -$nl$$end$$nl$$nl$###### -

I am a mac user. Under the code block, select all code and use the shortcut “command + ]” to indent all lines.


simple but works!

Lately I’ve been making a bullet with the code block directly under it, then selecting the entire code block and indenting (tab). Works and looks fine in Live Preview as long as there aren’t too many indents to begin with.

- change cursor color
	/* change cursor color */
	.markdown-source-view.mod-cm6 .cm-content {
	  caret-color: #ffa500 !important;

Screenshot 2023-03-08 at 16.48.28


even the possibility to indent the whole code block in live preview

Very needed feature

1 Like

found a solution: GitHub - mugiwara85/CodeblockCustomizer: Codeblock Customizer plugin for Obsidian

type “FOLD” and it works in live preview!


need this feature too

Thank you @radrad , this works: GitHub - mugiwara85/CodeblockCustomizer: Codeblock Customizer plugin for Obsidian

1 Like