I am trying to check if a mapping exists, and if true, unmap it. If I try to do it without checking it runs into error and exits. I guess I can also try to catch the error and add exception, but I can't find how to do it neither.
I tried:
if exists("map jjj")
unmap jjj
endif
But it returns that map jjj exists (even if not true) because if I run in normal mode
:map jjj
it returns n j * gj. That is, it returns j map exists.
I don't have further ideas
You can use maparg("jjj"), from the :help maparg:
maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
When {dict} is omitted or zero: Return the rhs of mapping
{name} in mode {mode}. The returned String has special
characters translated like in the output of the ":map" command
listing.
When there is no mapping for {name}, an empty String is
returned. When the mapping for {name} is empty, then "<Nop>"
is returned.
It will exactly match the {name} of the mapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With