I'm wondering if it is possible to check in vimscript if a key (or key combination) is already bound?
I know about the :map
command which lets me see visually which keys are bound to what actions, but what I am looking for is a way to check it programmatically and perform actions conditionally.
My concrete scenario is the following: I like the the possibility to dynamically/manually map <leader><leader>
to what I need in different cases. (eg. while programming python: run the script. Or compile while programming c++). I usually do it by typing :nmap <leader><leader> :!make && run program
manually while editing.
Now I want to check in my .vimrc
if the combination is already bound (by a plugin, or manually) and if not map it to a default action.
In short words: How can I map a key only if it is not already bound?
:h ftplugin
and:h 'makeprg'
. The idea is to set a differentmakeprg
for each filetype you're dealing with and having just a generic mapping which will call:make
. Otherwise maybe check:h :redir
to see how to get the output ofmap
into a variable.