I am using NeoVim, and I automatically define an abbreviation for the string W
every time the commandline mode starts.
However, it seems that commandline mode includes the search modes as well.
I do not want the abbreviation to exist in the search modes, so I want to delete it if it exists.
I tried maparg('W','c',v:true)
and mapcheck('W','c',v:true)
to check if W
is defined as an abbreviation in command mode, but they do not seem to work.
(here 'W'
is the abbreviation I want to check for, 'c'
stands for commandline mode, and true
is for abbreviation -- I think)
What am I doing wrong? Thanks
EDIT: adding my code for defining the abbreviation for W
:
autocmd CmdlineEnter,CmdwinEnter :,q: cnoreabbrev W w !git add %
(this allows me to add the file to the local git repo by typing :W<CR>
EDIT: Thanks to the answers below, the solution is:
cnoremap <expr> W (getcmdtype() == ':') ? "w !git add %" : "W"
Thank y'all -- it is very useful.
W
abbreviation?mapcheck('W', 'c', v:true)
works for me and returnswhatever
if I define it ascabbrev W whatever
, not sure what's the case with your particular setting...