diff --git a/visidata/undo.py b/visidata/undo.py
index <HASH>..<HASH> 100644
--- a/visidata/undo.py
+++ b/visidata/undo.py
@@ -29,8 +29,10 @@ def undo(vd, sheet):
                 undofunc(*args, **kwargs)
             sheet.undone.append(cmdlogrow)
             sheet.cmdlog_sheet.rows.remove(cmdlogrow)
+
+            vd.clearCaches()  # undofunc can invalidate the drawcache
+
             vd.moveToReplayContext(cmdlogrow)
-            vd.clearCaches()
             vd.status("%s undone" % cmdlogrow.longname)
             return
[undo-] clear drawcache before moving to pre-undo context

Per 6a4e<I>c<I>c<I>e<I>d<I>d<I>e5ed1, upon undo, VisiData tries
to move cursor to row/col of undone command.

If drawcaches are not cleared, VisiData could fail to find that pre-undo
context.