Passing Parameters into a Snippet

Was looking through all my snippets and was trying to tidy and consolidate a number of them.

One thing I noticed is that I have a lot of similar looking snippets

eg I have some snippets like below

ABC which generates lets say a link
BBC which generates
Radio -

etc etc

Now I know that you could use a dropdown field on form for this but what I was thinking was how cool it would be , and a step or 2 less, to pass in variable to a snippet

eg Lets say my new snippet is called /link

Now what I could was something like this


Etc etc

Now in the snippet I would just have a number of If/Else statements to get the parameters being passed into to build the link.

Not sure how useful this would be to others, or how much work would be involved in something like this.

eg you could have a new setting on a snippet that says this snippets expects parameters.

For these snippets you would NOT trigger on the /link part but trigger these when you get to the last ? character

Hope all the above makes sense to someone.

Hi @AndyPage

It's an interesting idea and one that comes up once a while (usually from users with previous programming experience :slightly_smiling_face:). Also see a similar post from a while ago: RegEx Shortcuts

What you are suggesting can be done using command packs. Command packs are groups of commands, and each command can accept positional and/or named properties (just as you described). Right now, users cannot create their own command packs, but we may enable this in the future.

With command packs, you will still need to create separate /radio, /bbc, /abc snippets. It will not work like the way you asked for (/link?radio). So, let's drill down on your quote above. I am curious to understand what is the primary issue you face in the current user experience with having one snippet with one dropdown? Is it organization, speed, muscle memory, etc.? Once I have a clearer idea then maybe I can provide a good temporary workaround.

This was my old answer. This may NOT work for you but I am keeping it for posterity.

You can use imported snippets like so:

/master snippet: you can add more conditional logic here but I just have a simple example


/bbc snippet:

{import: /master}{name="bbc"}

/fox snippet:

{import: /master}{name="fox"}

This will NOT work correctly in case you have multiple imports in the same snippet. For example,

{import: /master}{name="bbc"},{import: /master}{name="fox"}

will result in,

Thanks for the great and detailed reply. Glad I'm not the only loony to think of something like this in the past.

I think there are 2 reasons, both not very important :slight_smile:

  1. I like to push things to see what can be done with software and come up with use cases a little outside the box.
  2. Speed. I'm a keyboard person, so I'm MUCH quicker at typing lets says /link?bbc? than typing /link then clicking the drop-down, then clicking the correct option.

I've have been using the command snippets to build a library of reuseable snippets. I have a folder called Library. And in there I have items prefixed with lib eg lib_removeblanklines , lib_converttohash, lib_converttofilename etc

These are all reused in many other of my snippets so I don't have to repeat all the code again.

Nice to meet a fellow keyboard person :slightly_smiling_face: As a Vim user myself, I can relate to what you mean. Now, I understood your feature request and it makes sense.

From the technical perspective, it's not hard. But, the difficulty is in surfacing this feature to users who want it and implementing it in a consistent manner (few questions to think about: what if user doesn't want ? separator, what if user wants multiple fields, what if user wants to paste their clipboard data in between the ? separator, etc.).

So, given it's a very low in-demand feature, I don't think we are going to implement it anytime soon :frowning: Hope you understand!

I'll keep this thread updated if in the future we do implement this (or something similar)

Hey absolutely understand :+1: I think it was more of me brainstorming with myself :slight_smile: