Yes, you can wish for gems. If you wish for more than one, you'll only get one with probability n out of 6, where n is the number you wished for; otherwise you get the number you wanted. Thus, wishing for 2–5 dilithium crystals gives you at least one (worth $4500), and possibly more:
# wished for | max value | success rate | avg. value
1 | $4500 | 1 | $4500
2 | $9000 | 4/6 | $7500
3 | $13500 | 3/6 | $9000
4 | $18000 | 2/6 | $9000
5 | $22500 | 1/6 | $7500
6+ | n/a | 0/6 | $4500
However, note that:
The gems obtained by wishing will be unidentified. If you haven't identified dilithium crystals before, and cannot positively identify them (with a blessed touchstone, or with the spell or scroll of identify) before selling them, then shopkeepers will cheat you and only pay you a few zorkmids regardless of their true value.
Even if you can get the crystals identified, shopkeepers will only pay you at most 50% of their base value, and may pay you less depending on your class, level, worn equipment and just whether or not they feel like it (random 25% chance).
Each shopkeeper carries a limited amount of money, initially between $1100 and $4000. Once they're out of cash, they will only give you store credit (for 90% of the usual sell price), which you can only use to buy items from that specific shop. (Also, a bit annoyingly, if a shopkeeper can afford to pay only part of the sell price of an expensive item, they won't offer you credit for the remainder.)
Thus, even under ideal circumstances, the expect average profit from a wish for 3 or 4 dilithium crystals is only 50% × $9000 = $4500, which is less than the $5000 you could simply straight up wish for. Of course, if you do get lucky and get the full amount of gems you wished for, then 3 or more dilithium crystals will typically sell for more than $5000, but getting that result is far from guaranteed. And you'll never get all of that in cash, unless you've previously bought enough stuff from the shopkeeper with your own gold to make them extra wealthy.
Thus, if you're stuck in a shop with no money to pay your bill, but somehow happen to have a wish available, it's probably best to wish for:
- 5000 gold pieces, if that's enough to cover your debt,
- an escape item, such as a wand of teleportation, a wand of digging or a cursed potion of gain level,
- a cockatrice corpse (remember to wear gloves!) or a wand of death (make sure not to hit yourself on the rebound!) to kill the shopkeeper with, or
- a blessed figurine of an Archon.
Out of these options, the wand of digging and the cursed potion of gain level are probably the most reliable ones, being guaranteed to take you down or up a dungeon level respectively. Their major down side, of course, is that you'll have to deal with an angry shopkeeper and a bunch of Kops the next time you return to that level. Still, depending on where the shop is located and which direction you choose, you can at least spend a while in other parts of the dungeon to buff yourself up and/or to collect more gold to pay off the shopkeeper.
Stoning the shopkeeper with a cockatrice corpse, or zapping them with a wand of death, avoids this problem, but carries the risk that you'll miss and waste a turn (not to mention the intrinsic risks of both items, which can easily kill you if you're careless). Shopkeepers have AC 0, so the wand has a fixed 20% chance of missing. (Bouncing the death ray off a wall can reduce this, but is very risky unless you have reflection.) The hit chance for melee attacks depends on your to-hit roll, but is usually better than for wands; however, note that whacking things with a dead cockatrice doesn't benefit from any weapon skill bonuses.
The blessed figurine of an Archon, when applied, has an 80% chance of producing a tame Archon that should easily kill the shopkeeper; all you need to do is stay out of the way. However, beware the 10% chance of the Archon being hostile instead.
You might also consider wishing for some generic combat item, such as blessed greased fixed +2 SDSM (which will improve your AC and protect you from most of the wands carried by shopkeepers) or GDSM (if you already have reflection from another source) or an artifact weapon such as Grayswandir or Stormbringer, and hoping that it will be enough to let you fight the shopkeeper and win. This has the advantage that the item you wish for can remain a useful part of your ascension kit for the rest of the game, but carries the risk that, unless your other gear and stats are already fairly decent, a single powerful item may not be enough to let you survive the fight.
There are several other possible wishes that could be situationally useful. For example, if you already have some means of polymorphing yourself, a ring of polymorph control might be useful. Then again, you could just wish for S/GDSM and polymorph yourself while wearing it, which will turn you into a dragon that should be more than able to take on a shopkeeper.