Reputation: 4061
Is there a function in Vim to get the list of all current mappings as a dictionary? (I know about :map
command.)
If no (it seems so), is there a decent workaround?
Here is the practical motivation for this question: i would like to be able to clear all key mappings except those that start with <Plug>
.
Upvotes: 3
Views: 309
Reputation: 56438
Nothing I could see either. You could use :redir
to get the map output into a register and manipulate that. This snippet of vim script will do the job:
redir @a
silent map
redir END
let l = split(@a, '\n')
Now l
contains a list of mappings, though parsing each entry might be a pain.
To filter these for those not containing <Plug>
add this line:
call filter(l, 'v:val !~ "<Plug>"')
An example of a script to unmap non-<Plug>
entries could be:
redir @a
silent map
redir end
let l = split(@a, '\n')
call filter(l, 'v:val !~ "<Plug>"')
for line in l
let type = line[0]
let thekey = split(line[1:len(line)], ' \+')[0]
try
exec type. 'unmap '. thekey
catch /E31/
endtry
endfor
Upvotes: 4