Something totally obvious that has never occurred to me: if you use the vim shell you can save your shell history with :w
:w