diff --git a/src/blog/custom-syntax-highlighting.md b/src/blog/custom-syntax-highlighting.md new file mode 100644 index 0000000..b3efd25 --- /dev/null +++ b/src/blog/custom-syntax-highlighting.md @@ -0,0 +1,89 @@ +--- +name: Custom Syntax Highlighting in (Neo)Vim +slug: custom-highlighting +published: 2026-01-17 +labels: +- vim +- rust +previewLines: 22 +--- + +*Hopefully this post can be found by someone trying to answer the same questions I was, and maybe save some time.* + +Recently while working on closer integration between [Rust and WGSL shader code](/generating-shader-code-1), I looked into what it would take to get syntax highlighting working seamlessly. With a snippet like this: + +```rust +fn do_something() -> Option<()> { + // something + None +} + +const SHADER_SOURCE: &'static Shader = wgsl!(r#" + struct VertexOutput { + @builtin(position) clip_position: vec4, + } + + @vertex + fn vs_main( + vertex: ModelVertexData, + instance: InstanceDataWithNormalMatrix, + ) -> VertexOutput { + // ... + } +"); +``` + +...we want to be able to edit the "embedded" shader code as seamlessly as possible - it should look like this: + +```wgsl +struct VertexOutput { + @builtin(position) clip_position: vec4, +} + +@vertex +fn vs_main( + vertex: ModelVertexData, + instance: InstanceDataWithNormalMatrix, +) -> VertexOutput { + // ... +} +``` + +You may have seen this (multiple syntax highlighting languages used in the same file) for things like JSX or HTML with `