<![CDATA[Carrot Games]]> http://community.carrot-games.com Smartfeed extension for phpBB <![CDATA[Game Programming :: Snippets: The IDE feature from the 1990s nobody told you about :: Author celes]]> 2026-09-14T16:21:50+00:00 2026-09-14T16:21:50+00:00 http://community.carrot-games.com/viewtopic.php?f=10&t=56&p=121#p121

In VSCodium snippets are quite easy. Browsing the docs today instead of guessing taught me a couple of cool tricks today so I think it's worth a read: https://code.visualstudio.com/docs/edit ... edsnippets

I never thought I'd be the kind of dev to get into snippets :blobcatthink: To me, what made them really click is how you can have a snippet config file under .vscode/snippets.code-snippets in your repository and every clone of the repo gets the same snippets. I'm sure every editor in existence has had this feature for over twenty years, it just didn't click until recently that snippets are more useful are a per-project thing, not a per-user thing. You can still have both of course.

So what do I use snippets for? One thing is to "remember" the boilerplate. It's not the kind of boilerplate I want to eliminate, that one goes away. :akko_smile: But sometimes you just want to type faster. For example: I always forget how to create new editor plugins. I can go look at another plugin and copy-paste the relevant bits, it takes a minute, so it's not like this saves a significant portion of my time, but being able to type editorpl and hit return to get my plugin boostrapped is nice. It keeps me in the zone, which is important.

Code: Select all

"New editor plugin ": {
	"scope": "cs,csharp",
	"prefix": "editorplugin",
	"body": [
		"public partial class $1: EditorPlugin {",
		"    public void EditorLoad(Editor e) { }",
		"",
		"    public void EditorUpdate(Editor e) { }",
		"}",
	],
	"description": "Create a new Game Singleton"
},
But the simplest snippets are actually the ones that I use the most and save the most time. These lil' fuckers I use daily, several times. Typing getass and instead of ass this gets me the assets singleton (I know, disappointing :pensivecat:). I don't even remember what the original line looked like. If you've caught any of the streams you've surely seen it, it's crazy how much typing this saves:

Code: Select all

"Get the asset manager": {
	"scope": "cs,csharp",
	"prefix": "getassets",
	"body": [
		"var assets = Singletons.Assets();"
	]
},
"Get the renderer": {
	"scope": "cs,csharp",
	"prefix": "getrenderer",
	"body": [
		"var renderer = Singletons.Renderer();"
	]
},
Then there's creative snippets covering up for missing language features. Here I wrote this because C# doesn't have a "prefill all the parameters to this function" helper and my particle struct has a bazillion fields:

Code: Select all

"Construct a particle": {
	"scope": "cs,csharp",
	"prefix": "newparticle",
	"body": [
		"Particle.New(",
		"    position: Vec2(0, 0),",
		"    lifetime: 1,",
		"    zIndex: DrawOrder.Particles.ToZ(),",
		"    rotation: 0f,",
		"    direction: Vec2(0),",
		"    gravity: Vec2(0),",
		"    speed: 0,",
		"    size: Vec2(1),",
		"    color: Color.White,",
		"    angularVelocity: 0f,",
		"    blendMode: BlendMode.AlphaBlend,",
		"    texture: null,",
		"    hFlip: false,",
		"    vFlip: false,",
		"    flipbookFrames: (numFrames: 4, fps: 12)",
		")"
	]
},
And perhaps the ones I feel the proudest for are the dialogue script ones. Writing dialogue gets tiresome really fast if you're typing anything other than the dialogue text. I could've built a streamlined imgui widget for that, but I like keeping my dialogue data as simple XML files, so I desperately needed something to avoid wrist pain from typing so much < and >.

In the end, my dreams of a dedicated VSCode extension (which I actually have, for other more advanced use cases, but that's a story for another day) were stopped by these two lil' snippets:

Code: Select all

"Dialogue: Character": {
	"scope": "xml",
	"prefix": "character",
	"body": [
		"<character character=\"${1|lynchpin,renna,renna-hub,scientist,squatter,informant,messenger|}\" mood=\"${2|grin,happy,sigh,angry,laugh|}\"/>"
	]
},
"Dialogue: Talk": {
	"scope": "xml",
	"prefix": "talk",
	"body": [
		"<talk>$1</talk>"
	]
}
Crazy, right? Notice the ${1|one,two,three|} syntax? That thing gives me auto-completion for the placeholder value and it saved me a VSCode extension. Cool stuff.

And you'll say: But Celes, these snippets are not in sync with your code and need manual adjustment, surely we can do better? Macros perhaps? Code generation? Well, while you were doing better I was getting the code written. That's the point of snippets. Like the blue philosopher said: "Long as the voice inside drives me to run and fight, It doesn't matter who is wrong and who is right".

Anyway, I'm glad I took the time to introduce snippets into my workflow. It took a while for me to develop the neural pathways that make my snippet sense tingle when I've been typing a recurring pattern too much, but now they're finally there :blobcatnodfast:]]>


In VSCodium snippets are quite easy. Browsing the docs today instead of guessing taught me a couple of cool tricks today so I think it's worth a read: https://code.visualstudio.com/docs/edit ... edsnippets

I never thought I'd be the kind of dev to get into snippets :blobcatthink: To me, what made them really click is how you can have a snippet config file under .vscode/snippets.code-snippets in your repository and every clone of the repo gets the same snippets. I'm sure every editor in existence has had this feature for over twenty years, it just didn't click until recently that snippets are more useful are a per-project thing, not a per-user thing. You can still have both of course.

So what do I use snippets for? One thing is to "remember" the boilerplate. It's not the kind of boilerplate I want to eliminate, that one goes away. :akko_smile: But sometimes you just want to type faster. For example: I always forget how to create new editor plugins. I can go look at another plugin and copy-paste the relevant bits, it takes a minute, so it's not like this saves a significant portion of my time, but being able to type editorpl and hit return to get my plugin boostrapped is nice. It keeps me in the zone, which is important.

Code: Select all

"New editor plugin ": {
	"scope": "cs,csharp",
	"prefix": "editorplugin",
	"body": [
		"public partial class $1: EditorPlugin {",
		"    public void EditorLoad(Editor e) { }",
		"",
		"    public void EditorUpdate(Editor e) { }",
		"}",
	],
	"description": "Create a new Game Singleton"
},
But the simplest snippets are actually the ones that I use the most and save the most time. These lil' fuckers I use daily, several times. Typing getass and instead of ass this gets me the assets singleton (I know, disappointing :pensivecat:). I don't even remember what the original line looked like. If you've caught any of the streams you've surely seen it, it's crazy how much typing this saves:

Code: Select all

"Get the asset manager": {
	"scope": "cs,csharp",
	"prefix": "getassets",
	"body": [
		"var assets = Singletons.Assets();"
	]
},
"Get the renderer": {
	"scope": "cs,csharp",
	"prefix": "getrenderer",
	"body": [
		"var renderer = Singletons.Renderer();"
	]
},
Then there's creative snippets covering up for missing language features. Here I wrote this because C# doesn't have a "prefill all the parameters to this function" helper and my particle struct has a bazillion fields:

Code: Select all

"Construct a particle": {
	"scope": "cs,csharp",
	"prefix": "newparticle",
	"body": [
		"Particle.New(",
		"    position: Vec2(0, 0),",
		"    lifetime: 1,",
		"    zIndex: DrawOrder.Particles.ToZ(),",
		"    rotation: 0f,",
		"    direction: Vec2(0),",
		"    gravity: Vec2(0),",
		"    speed: 0,",
		"    size: Vec2(1),",
		"    color: Color.White,",
		"    angularVelocity: 0f,",
		"    blendMode: BlendMode.AlphaBlend,",
		"    texture: null,",
		"    hFlip: false,",
		"    vFlip: false,",
		"    flipbookFrames: (numFrames: 4, fps: 12)",
		")"
	]
},
And perhaps the ones I feel the proudest for are the dialogue script ones. Writing dialogue gets tiresome really fast if you're typing anything other than the dialogue text. I could've built a streamlined imgui widget for that, but I like keeping my dialogue data as simple XML files, so I desperately needed something to avoid wrist pain from typing so much < and >.

In the end, my dreams of a dedicated VSCode extension (which I actually have, for other more advanced use cases, but that's a story for another day) were stopped by these two lil' snippets:

Code: Select all

"Dialogue: Character": {
	"scope": "xml",
	"prefix": "character",
	"body": [
		"<character character=\"${1|lynchpin,renna,renna-hub,scientist,squatter,informant,messenger|}\" mood=\"${2|grin,happy,sigh,angry,laugh|}\"/>"
	]
},
"Dialogue: Talk": {
	"scope": "xml",
	"prefix": "talk",
	"body": [
		"<talk>$1</talk>"
	]
}
Crazy, right? Notice the ${1|one,two,three|} syntax? That thing gives me auto-completion for the placeholder value and it saved me a VSCode extension. Cool stuff.

And you'll say: But Celes, these snippets are not in sync with your code and need manual adjustment, surely we can do better? Macros perhaps? Code generation? Well, while you were doing better I was getting the code written. That's the point of snippets. Like the blue philosopher said: "Long as the voice inside drives me to run and fight, It doesn't matter who is wrong and who is right".

Anyway, I'm glad I took the time to introduce snippets into my workflow. It took a while for me to develop the neural pathways that make my snippet sense tingle when I've been typing a recurring pattern too much, but now they're finally there :blobcatnodfast:]]>
<![CDATA[Game Programming :: Re: Snippets: The IDE feature from the 1990s nobody told you about :: Reply by Sugui]]> 2026-09-14T17:11:04+00:00 2026-09-14T17:11:04+00:00 http://community.carrot-games.com/viewtopic.php?f=10&t=56&p=122#p122
Probably not many people realizes that, because for programming languages, it's easy to find an extension that gives you language snippets for a while loop, or a for-each loop. But for project specific snippets, no one would be doing the snippets except yourself :blobfoxthinksmart:

No one is giving you a getass*enter* for free :pensivecat:]]>

Probably not many people realizes that, because for programming languages, it's easy to find an extension that gives you language snippets for a while loop, or a for-each loop. But for project specific snippets, no one would be doing the snippets except yourself :blobfoxthinksmart:

No one is giving you a getass*enter* for free :pensivecat:]]>
<![CDATA[Game Programming :: Re: Snippets: The IDE feature from the 1990s nobody told you about :: Reply by celes]]> 2026-09-15T17:37:35+00:00 2026-09-15T17:37:35+00:00 http://community.carrot-games.com/viewtopic.php?f=10&t=56&p=123#p123
Sugui wrote: Mon Sep 14, 2026 5:11 pm Probably not many people realizes that, because for programming languages, it's easy to find an extension that gives you language snippets for a while loop, or a for-each loop.
Yes!! This so much. I wrote this yesterday thinking: People will think I'm dumb and this is obvious because everybody already knows. But you're right! Programming language extensions giving you all those silly useless snippets prove how widespread the wrong minset is! Very good point :blobcatthink:]]>
Sugui wrote: Mon Sep 14, 2026 5:11 pm Probably not many people realizes that, because for programming languages, it's easy to find an extension that gives you language snippets for a while loop, or a for-each loop.
Yes!! This so much. I wrote this yesterday thinking: People will think I'm dumb and this is obvious because everybody already knows. But you're right! Programming language extensions giving you all those silly useless snippets prove how widespread the wrong minset is! Very good point :blobcatthink:]]>