Good News Everyone
A setting has just been added to the Insiders Build v1.64 to give better control or disable undo operations on files:
Explorer: Enable Undo
Controls how the Explorer participates in undoing file and folder
edits
It defaults to true though so you might want to change it to false. So that if you do a undo operation when a file or folder has focus in the Explorer, you will get a warning confirmation dialog.
This new setting should be in Stable v1.64 early February, 2022.
Explorer Undo: Confirm/Enable Undo
The file explorer has long supported an undo stack to revert file and
folder edits. This iteration we've added prompts to make more explicit
what actions an undo in the explorer will perform, and provided a
setting to disable undo in the explorer entirely
(explorer.enableUndo). By default the explorer will now prompt
before all potentially destructive actions ("explorer.confirmUndo": "default"), but this can be changed to the old behavior ("light"),
or "verbose", to prompt before all actions.
Older Answers:
I don't see a relevant setting but you could do this so that undo only works when you have editorFocus (in your keybindings.json):
{
"key": "ctrl+z",
"command": "undo",
"when": "editorFocus"
},
{
"key": "ctrl+z",
"command": "-undo"
}
As you probably know, v1.53 is at least adding a confirmation dialog for undo operations in the Explorer, see v1.53 release notes confirmation dialogs.
If a user tries to quit VS Code while there is a file operation in
progress, we now show a confirmation dialog. We also show a
confirmation dialog for destructive undo operations from the Explorer.
It isn't a setting to prevent even trying to do it, but does provide some protection.