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.

24 Likes

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

7 Likes

Maybe you can try the callouts function

[!info]-
![[Document#blockreference]]

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!

5 Likes

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.

2 Likes

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$###### -

2 Likes

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

3 Likes

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
	```css
	/* change cursor color */
	.markdown-source-view.mod-cm6 .cm-content {
	  caret-color: #ffa500 !important;
	}
	```

Screenshot 2023-03-08 at 16.48.28

3 Likes

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!

6 Likes

need this feature too

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

2 Likes

Try this plugin: Obsidian-Code-Styler

1 Like

Thank you so much @oat , This plugin is a life saver :slight_smile:

1 Like