He was educated at Selkirk Grammar School, Loretto, and at the Edinburgh Academy, St Andrews University and at Balliol College, Oxford, where he took a first class in the final classical schools in 1868, becoming a fellow and subsequently honorary fellow of Merton College. He soon made a reputation as one of the most able and versatile writers of the day as a journalist, poet, critic, and historian. In 1906, he was elected FBA.
He died of angina pectoris at the Tor-na-Coille Hotel in Banchory, Banchory, survived by his wife. He was buried in the cathedral precincts at St Andrews.