Search...Search plugins and themes...
⌘K
Sign in
  • Get started
  • Download
  • Pricing
  • Enterprise
  • Account
  • Obsidian
  • Overview
  • Sync
  • Publish
  • Canvas
  • Mobile
  • Web Clipper
  • CLI
  • Learn
  • Help
  • Developers
  • Changelog
  • About
  • Roadmap
  • Blog
  • Resources
  • System status
  • License overview
  • Terms of service
  • Privacy policy
  • Security
  • Community
  • Plugins
  • Themes
  • Discord
  • Forum / 中文论坛
  • Merch store
  • Brand guidelines
Follow us
DiscordTwitterBlueskyThreadsMastodonYouTubeGitHub
© 2026 Obsidian

Clang-Format Code Blocks

Ömer KaraÖmer Kara31 downloads

Format fenced code blocks in your notes using clang-format.

Add to Obsidian
Clang-Format Code Blocks screenshot
  • Overview
  • Scorecard
  • Updates2

Obsidian plugin. Formats fenced code blocks in your notes using clang-format.

Requirements

  • Desktop Obsidian only (uses Node's child_process, not available on mobile).
  • clang-format installed and reachable (on PATH, or point directly at the binary in settings).

What it does

Scans the active note for fenced code blocks tagged with one of the languages clang-format supports, pipes each block's contents to clang-format, and replaces the block in place with the formatted output. Other languages and nested fences are left untouched.

Recognized fence tags: c, h, cpp/c++/cc/cxx, hpp/hh/h++/hxx, objc/objective-c/m, objc++/objective-c++/mm, cs/csharp, java, js/javascript/jsx/mjs/cjs, ts/typescript/tsx, json/jsonc, proto/protobuf, textproto/textpb/txtpb, tablegen/td, verilog/v, systemverilog/sv.

Commands

  • Format all code blocks in current note — formats every matching block in the active note.
  • Format code block at cursor — formats only the block the cursor is currently inside.

Assign hotkeys to these in Settings -> Hotkeys.

Format on save

Enabled by default. Formatting only runs on an explicit save (Ctrl/Cmd+S) — never while you're still typing — so it won't rewrite a block out from under you mid-edit. Failures still show a notice; successful auto-formats are silent. Toggle off in plugin settings if you don't want this.

This works by wrapping Obsidian's internal editor:save-file command (the same approach the Linter plugin uses), since there is no public "before save" hook. It's guarded so a future change to that internal shape just makes format-on-save a no-op rather than breaking saves, and the wrap is undone if you disable the plugin.

Settings

  • Format on save — see above.
  • clang-format executable — path or command name. Default: clang-format.
  • Style — File (use a .clang-format config) or a built-in style name (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU).
  • Custom .clang-format file — only used when Style is File. Optional absolute path, or path relative to the vault root, to a specific config file. If set, that exact file is used for every note. If left blank, clang-format searches upward from the current note's folder for a .clang-format file.
  • Test connection — runs clang-format --version and, if a custom style file is set, checks it exists.

Installing manually (not yet in the community directory)

Create <your-vault>/.obsidian/plugins/clang-format-code-blocks/ and copy main.js and manifest.json from a release (or from a local build, see below) into it. Then enable the plugin in Settings -> Community plugins.

Development

npm install
cp deploy.config.example.json deploy.config.local.json   # then edit vaultPluginDir
npm run dev          # watch build
npm run build         # production build
npm run deploy         # copy main.js + manifest.json into vaultPluginDir
npm run build:vault   # build + deploy in one step

main.ts is the source, bundled to main.js via esbuild. deploy.config.local.json is gitignored — it points npm run deploy at your own vault's plugin folder. Reload Obsidian (or disable/re-enable the plugin) after deploying.

License

MIT.

HealthExcellent
ReviewSatisfactory
About
Format fenced C-family and other clang-format–supported code blocks in your notes by piping each block through clang-format and replacing it in place. Scan the active note or format only the block at cursor, with optional format-on-save (desktop only; clang-format must be installed).
CodeFormatting
Details
Current version
1.0.2
Last updated
2 weeks ago
Created
2 weeks ago
Updates
2 releases
Downloads
31
Compatible with
Obsidian 0.15.0+
Platforms
Desktop only
License
MIT
Report bugRequest featureReport plugin
Author
Ömer KaraÖmer Karaoemer-kara
GitHuboemer-kara
  1. Community
  2. Plugins
  3. Code
  4. Clang-Format Code Blocks

Related plugins

Mermaid Tools

Improved Mermaid.js experience: visual toolbar with common elements and more.

Admonition

Admonition block-styled content.

Templater

Create and use dynamic templates.

Linter

Format and style your notes. Linter can be used to format YAML tags, aliases, arrays, and metadata; footnotes; headings; spacing; math blocks; regular Markdown contents like list, italics, and bold styles; and more with the use of custom rule options.

Sort and Permute lines

Sort and Permute lines in whole file or selection.

PlantUML

Generate PlantUML diagrams.

Kroki

Render Kroki diagrams.

Colored Text

Color the selected texts.

Code Space

Professional code file management with visual dashboard, syntax highlighting editor, and Markdown embedding.

List Callouts

Create simple callouts in lists.