Toad World® Forums

Snippet : snippet token from clipboard


Is there a way to have a token in the snippet that pastes the content of the clipboard into the snippet ?

Example "select * from product where product_id = $$paste-from-clipboard$$ and group = 'XYZ' and other_things = 0", with shortcut 'selprod'

Say I somehow have a product_id on the clipboard that I copied from somewhere (from a support email for instance, or from the ticketing system). It would have been nice if I immediately could run the snippet and the product_id from the clipboard is automatically pasted into the resulting query.

Now I first have to paste the product_id in toad, then select it, en then press ctrl-space to open the 'insert snippet', then have to select "SQL(SQLSERVER)" then have to scroll down in the list to find my snippet (as I can't type the shortcut "selprod" in that list).

It would be easier to just type "selprod" in toad editor followed by ctrl-space.

Any ideas ?

Don't have your exact requirement in the product today, but you can get pretty close by defining snippets that have a "SurroundWith" type, instead of expansion.

In particular, with the built-in $end$ snippet token, you can accomplish pretty close to your end result by

  1. Copy to Clipboard
  2. Type the snippet shortcut name and hit Ctl-Space to expand
  3. Ctl-V to paste your clipboard contents within the snippet code at the $end$ token marker

See vid below...

Hi Gary,

Thanks for the response. This is indeed a good idea.

Unfortunately this won't work if you need the pasted value in multiple places.

For instance with the following oneliner snippet (where I'd like to paste the temp tablename) :
if object_id('tempdb..$selected$') is not null drop table $selected$

Kind regards,

Hey Pascal, but this does work... as long as you're defining your code snippets with a type of "Surrounds With". See snap flow below...

Hi Gary,

Great, that actually works.

Thanks a lot !