Implement vim undo with cleanup