Meal planning is the way to go. If you don't plan your meals, there comes a day when you're wondering what to have for dinner, and you wonder for so long you can't be bothered anymore and buy something easy to prepare - processed food, and you pay for someone else to process it. You'll also instinctively go for the higher energy foods with lots of sugar.
For example, a jar of pasta sauce will be more expensive than a couple of cloves of garlic, a carrot, stick of celery, onion, a zucchini and a couple of tins of tomatoes. And a box of added vitamin added fibre corn flakes will be more expensive than a bag of oats. Raisin toast will be more expensive than plain bread with jam.
Buying spontaneously also means buying smaller portions. You buy 1kg of rice instead of 20kg, and 20 lots of 1kg cost more than a 20kg bag.
Meal planning needn't be strict, you just have your standard ingredients you always buy. We're always getting tins of tomatoes for sauces, UHT milk (it's cheapest), rice, pasta, minced meat, chicken, and so on. You watch for which are the cheapest brands or these things are on sale and then you get them in bulk. Tuna is cheap this week, 90c a can instead of $1.20, okay let's get 20 tins.
Fruit and vegies make up about half of our grocery bill (about $550 a month for two adults and one child, this also includes things like shampoo). With those, again many things like onions and potatoes you can buy in bulk, they'll last for a month at least. The seasonal fruit and vegies are usually $2/kg, the out-of-season ones $6-$10/kg. So now it's summer and we're eating bananas and oranges, come winter we'll have more stonefruits like peaches. I go into the greengrocers and look for the cheap stuff.