There are several standard ways to use cnoreabbrev / cnoremap for this: before replacing X with X check if it is the only character on the command line:
cnoremap <expr> X (getcmdtype() is# ':' && empty(getcmdline())) ? 'x' : 'X'
or
cnoreabbrev <expr> X (getcmdtype() is# ':' && getcmdline() is# 'X') ? 'x' : 'X'
. The difference is that at first you won’t type :Xfoo (translate to :Xfoo ), there won’t be a second one, but don’t allow input :X! (translates to :X! which really makes sense, unlike :X! ).
There are definitely no differences for the search ( /X is fine), input() prompt, etc., and no difference if the typed X not the first.
source share