Remap command :x

I am trying to unlearn the use of :x to write/quit the file I am editing. I thought I had a brilliant solution using the following remap in my vimrc.

cmap x :echom “Use :w instead”

So this works great when I type :x however an unintended side effect is that i can’t search for anything with an x in it the map get’s triggered.

Any ideas on how to remap only :x and still allow /x in search ?

I haven’t tried it, but I think cmdalias will make this pretty easy to do, you just need to define your own custom command first (e.g. Remindme) to echo the message.

thanks for the tip.
I ended up cobbling together this function. If it ends up failing me i’ll go the cmdalias route.

cnoremap x WhatXmap()
function! WhatXmap()
let cmdtype = getcmdtype()
if cmdtype == ':'
return "Use :w instead"
return "x"