Refactor out GetNextSelection; add command replace_next

#454 
Same as above.