I use i3wm, and to map cap lock to escape, I run:
setxkbmap -option caps:swapescape
This works fine, but sometimes while hitting the F1 key, my pinky can accidentally hit the Escape key, which turns on CapsLock.
Gnome has a very nice way to do this, where Shift + Escape = CapsLock. Hitting Escape on its own will do nothing.
vi/vim
From my understanding, Esc was originally where the Caps lock is on earlier keyboard layouts. That’s why it’s bound to that in Vim. It’s a holdover, so it makes sense to switch them back.