I had a file on a USB stick, and I was editing it but then I saved it and pulled out the USB. Later when I plugged it back in, the file had a size of 0 as well as the backup made by kwrite(I a running linux). What happened? And how can I recover it?
Re the what happened: you were hit by pebcac. With multi-user multi-tasking OSes it's never safe to just pull a USB storage device after a "write/save" activity because modern OSes cache writes, too, unless you specifically disable it. Even WHEN you disable it it's still a potentially hazardous thing to do, depending on the size of your write, and the write speed.
Re recovery: I'm afraid there is none in your specific case. You may get lucky with some forensic tool, e.g. photorec
in any linux distribution you must always "eject" the device before you pull it out by right clicking on the device and find in menu. always wait until any flashing indicators on flash dirve are finished and even then i like to wait about 10-15 seconds. I first encountered this on ubuntu 7.10 nothings changed since.