People say that St. Andrews just has three streets. I went on a MUN conference there last year, and proved this to be correct.
But really, from my brief time there I struggled to see many advantages over Edinburgh. The 'tight-knit' community thing rather seemed to me because of it's very small size, as well as the fact that there are no clubs (or certainly not any you would want to go to), so people just end up hanging around with each other more. That is not to say that Edinburgh does not have flat parties too though. As long as you engage with a few societies you will be fine. On average during term time this year I have been invited to two-three house parties a week, which has been pretty fun. St. Andrews' Students' Union is slightly cheaper than Edinburgh's but the fact that it is the only viable nightlife spot undermines the importance of that, as well as the fact that Edinburgh has two such buildings, one of which is literally a castle. Edinburgh also has The Hive, which is quite special.
Also as a History student Edinburgh has the advantage of being right next to the National Library of Scotland, a copyright library, which I have found vital. Too often the books I've needed have not been in the Main Library and I have had to go there; that's partly Edinburgh's fault for not having enough copies, but at the same time there's never going to be enough of everything on any popular course. Academically Edinburgh is fine, there's a lot of courses which will suit all interests. Most lecturers are very good. Essays take three weeks to be returned, which is pain but you get used to it. Feedback is sometimes average, but mostly informative even if brief. From what I have heard I think this really sharpens/improves in Honours years, but I am only in second year so cannot personally testify. Tutorials are normally good as long as you do the reading, to get the most out of them you have to do the work, but that's quite obvious. They are a maximum of 12 people I believe, and are taken by an even mix of doctoral students and faculty members, which is good.
In terms of St. Andrew's history and places of interest, I learned the same, and more about it in a day than my friend who had studied there for a year. There's just not that much there. In Edinburgh it is possible to discover entirely new parts of the city almost every day, while exploring. St. Andrews is certainly pleasant, but really only for a day trip or weekend. Also unless you are coming from Fife it is a big pain to get to due to the non-presence of a train station.
Halls in Edinburgh are fine, I would advise living in Pollock Halls though because it's a nice mini-campus environment. Edinburgh flats after first year are pretty cool but can be bad/expensive. Students live around the city but it is still small enough to walk anywhere so there are flat parties all the time. Marchmont and Newington are probably the most 'studenty', but I definitely want to live in Tollcross in 4th year because of its great location, and I will not be getting drunk so much.
My degree course is quite similar to what you will be doing, so if you have any more questions academically or otherwise about Edinburgh let me know.