I use an app called Our Groceries. Every time I think about something we need to buy at the grocery store, I add it to the list. Every time I see that we are running low of an item that we use regularly, I add it to the list. I tend to have three separate lists of items that can only be found in certain stores: grocery store, organic grocer, and Costco.
If it's a shelf-stable item that we use regularly, then I tend to buy double what we usually need. For example, I try to keep two unopened boxes of pasta in the pantry at all times. Once I use a box of pasta, I add "pasta" to the list and replenish the supply. Sometimes we may have to cook a lot of pasta--or we haven't had time to go to the grocery store since I added it to the list; that is when it's helpful to have an extra box around.
The nicest thing about the app is that lists can be shared and updated in real-time across multiple devices. If I'm driving home, and I have time to stop by the grocery store, I'll text Mrs. Swede to update the grocery list. When I get there, her list of items that we need are on my phone.