I often write the active Vim buffer with :w, then reload the buffer with :e to reset the undo/redo history. I do this so often, I've updated my .vimrc file with a command mapping for :we, to do both in one step:
" Reset undo/redo buffer on reload
set undoreload=0
" Write and clear undo/redo buffer
cnoremap we w\|e
However, this mapping is still executed if I enter we in the middle of the command line; for example, :s/answer/42/ is expanded to :s/answ|er/42/. Is it possible to map we only if it appears at the start of the command?