How to test if an escape sequence is currently mapped

13 views
Skip to first unread message

cjsmall

unread,
Feb 17, 2020, 4:12:40 PM2/17/20
to vim_use
Thanks to everyone who offered very helpful suggestion regarding my previous question on the best way to conditionally map function keys using autocmd BufReadPre, when editing particular files.

I wanted to unmap the keys upon exiting the file and have done that also using aucocmd BufLeave.  However, I found that an attempt to unmap a key sequence that isn't currently mapped results in an error.  If there a way to perform a test to see if a particular key or escape sequence is mapped, and only then unmap it?  Something like:

:if ismapped <Esc>[1;3S
:    nunmap <Esc>[1;3S
:    iunmap <Esc>[1;3S
:endif

If I can do this, then I can write a single universal function that handles all conditions. 

And if there is some sort of test, is it generic to all mappings or particular to the mode such as imap, nmap, etc?

Thanks!
Reply all
Reply to author
Forward
0 new messages