This is a bizarre question, but I think I see your point.
We always require for our writing products to be durable: we want to be able to observe them again sometime later.
If you write on a gas using a spray even if you are very precise and you remove gravity in order not make your "ink" fall on the ground, your writing will dissolve in really few seconds: the molecules of the air(or gas) will hit frenetically your ink, which will undergo a diffusion around the surrounding gas.
If you are at zero temperature (-273 °C) this will not happen, but you cannot really talk about air and ideal gases in that case.
If you use fluid (like water, liquid ink or even honey) and you remove gravity then your writing will last longer. Of course you will need something different from the usual pens because you need to eject the substance you are using as ink since no capillarity helps it out of your writing device.
The problem in this case will be that whatever you use as ink is not fixed on a solid background and you can cause it to change shape if you touch it. Note that if you make your ink become solid after writing (like molten metal that solidifies or water that freezes) you will be fine, but maybe far from your idea of writing.
If your question was about how the usual pens work, the answer is capillarity: the material in contact with the tip of the pen attracts the ink out of the pen (try to keep the tip still on a point of a sheet and you will see the ink being "sucked out" in the paper). At the end of the day this is a result of surface tension and the behavior of liquids at an interface.