The question pretty much sums it up: Is there a way to clear all of the <leader> mappings set by plugin authors before proceeding to set my own custom mappings?

The only way I've seen to do this is to remove them individually with an autocmd or in the after/ directory, but I'd like to remove them all in one go without ever having to worry about it again, regardless of the plugins I may add in the future.

  • You don't need to clear existing mappings before creating yours.
    – romainl
    Nov 14, 2022 at 19:12
  • the question does not ask if there is a need to clear existing mappings, the question asked if there is a way to do so ... your comment is not helpful
    – dreftymac
    Nov 14, 2022 at 20:38
  • 1
    I guess I'm just being picky about not having any mappings that I didn't put there myself.
    – apostl3pol
    Nov 14, 2022 at 21:03

1 Answer 1


You can use maplist() to get a list of mappings; this returns a list with information about every custom mapping.

You can see the exact list of properties it returns in :help maplist(); the one important for us here is lhs ("left hand side"), which is the key mapping. For example for nnoremap <Leader>tc … it's set to '\ts', assuming that <Leader> is the default of \ (<Leader> is expanded when used, so it shows up as a backslash).

To unmap everything, you can use something like:

for m in maplist()
    if m.lhs[0] == '\'
        echo printf('unmap %s', m.lhs)
        exe 'unmap' .. m.lhs

Note that this doesn't necessarily truly remove all mappings, because some plugins may define buffer-specific mappings from an autocmd which will be applied every time a buffer is loaded. Unsetting those would be complex and error-prone, but you can run the above in your autocmd (although that would also remove your own mappings). In general it's probably a better strategy to configure the specific plugins, many have some sort of setting to prevent defining any mappings (and if they don't, creating a patch is usually easy, and thus far everyone I've sent a patch for this has accepted it).

  • Exactly what I was looking for, and thanks for the explanation of why it's still not ideal. I suppose I could maintain my own list of mappings to check against when running the autocmd, if I really want to go down this route.
    – apostl3pol
    Nov 15, 2022 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.