I've tried using the KDE's keyboard settings (Input devices -> Advanced -> Caps Lock behavior -> Swap Esc and Caps Lock), and it swapped them. Escape behaves as a Caps lock, but Caps lock now acts as ESC and it also changes register at the same time.
I used Gnome previously and achieved this using dconf-editor with custom xdb options. On tiling managers, I did this through an auto-loaded config file. But the problem was that when you unplug your keyboard, the settings are reset, since the script is only run on startup. So I want KDE do manage this by itself, which it fails to do for some reason.
How to properly configure Caps and ESC to be swapped on KDE without the issues I described (and preferrably without a .Xprofile script, since I want my settings to apply every time a keyboard is plugged in)?