Deleting Key Maps


Deleting a key mapping is pretty simple, and uses a call signature similar to the used to [create] the key mapping in the first place:

vim.keymap.del(
    {mode}, -- string or list
    {lhs}, -- string
    {opts} -- optional table
)

where mode and opts are the same as described in setting key mappings. When deleting key mappings, the mapping is deleted for only the modes specified, and opts supports only the buffer key, indicating whether want to delete a global or buffer-local key mapping.

This method will delete the key mapping, but in most cases key mappings are created in a configuration file. This means that it will reappear next time to start Neovim.

If the key mapping is created in your configuration files, deleting the mapping generally means deleting (or commenting out) the code that created it and restarting Neovim. The next section will discuss how to locate where key mappings are defined, which can help with this.

What if the key mapping you wish to delete comes from outside your configuration, such as from a plugin? There are several possible solutions available:

1) Review the plugin documentation

Most plugins that set key mappings will include instructions defining how to change them in the plugin's configuration. In most cases, this would be the best way to delete (or re-map) the plugins default key mappings.

1) Overwrite the key mapping

When you aren't able to delete or change the key mapping from with the plugin's configuration, the next option is to re-define that mapping to perform the action you want. In that case, simply create a new key mapping that performs the action you want. As long as this key mapping is executed after the plugin is loaded, this should be an effective solution. Review the search directories section for help ensuring that this command is executed after the plugin in question is loaded.

If you don't want the key mapping to do anything at all, another option would be to define a new key mapping, but set to a no-op (meaning, "no operation", or "do nothing") as follows:

vim.keymap.set(
    {mode}, -- string or list
    {lhs}, -- string
    "<Nop>",
    {opts} -- optional table
)

This literally tells Neovim to ignore the lhs, which is effectively the same as deleting the key mapping.