我正在尝试检查映射是否存在,如果是,则取消映射。如果我尝试在没有检查的情况下执行此操作,则会遇到错误并退出。我想我也可以尝试捕获错误并添加异常,但我也找不到方法。
我试过:
if exists("map jjj")
unmap jjj
endif
Run Code Online (Sandbox Code Playgroud)
但它返回map jjj
存在(即使不是真的),因为如果我在正常模式下运行
:map jjj
Run Code Online (Sandbox Code Playgroud)
它返回n j * gj
。也就是说,它返回j
map 存在。
我没有进一步的想法
您可以使用maparg("jjj")
, 来自: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.
Run Code Online (Sandbox Code Playgroud)
它将{name}
与映射的完全匹配。