I didn't plan ahead—I just went with the first cell-phone store I found, which happened to be Vodafone. (The major networks have stores everywhere in London, including in many train stations.) Pay-as-you-go SIM cards are free—you simply pay for the amount you want to use. I spent 10 GBP (approximately $15, according to XE.com) and got 300 local texts, 500 MB of internet data, and 100 minutes of calling time, which was more than enough for the five days I was in London. (Prepaid SIM plans vary widely—you can also buy international minutes, if you need to call home.) Start with the minimum amount you think you'll need—it's easy to "top up" your credit online, at many convenience stores, or even by phone.
I wish that I had done some research on providers instead of picking one at random—I later found out that only a few cell-phone companies in the UK have 4G service (the faster cell-phone network), and Vodafone is not one of them. Using a 3G network after becoming used to 4G speed was definitely painful, and I had trouble getting internet data in some areas.
Providers also differ in what they give for the price, so shop around before you go. If you're planning on calling or texting local contacts, check and see which networks they use, as it's often free to call people who use the same provider.