I haven’t used it myself, but a plugin exists for this: Plugin for keeping the filename and first heading of a file in sync