Mert Nuhoglu
Mert Nuhoglu

Reputation: 10153

How does <Plug> work in Vim?

I didn't understand what <Plug> does and how to use it. I read the documentation but it is not clear to me.

Upvotes: 2

Views: 456

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172768

<Plug> is just a special, synthetic key that is never actually sent by the keyboard; i.e. you cannot type it.

With this, the :map functionality that comes from old vi can be used as an abstraction layer for plugins.

Instead of directly mapping plugin functionality to a fixed key, plugins define a <Plug>PluginNameFunctionName mapping, which can then be freely remapped to the desired key by the user. As Vim allows to check for existing mappings (via hasmapto()), plugins can also define a default mapping if none was specified by the user.

TL;DR

  • for your own personal mappings, you can ignore <Plug>
  • if you use a plugin and need to customize its mappings, :map your own left-hand side to the <Plug>-mapping(s) provided by the plugin
  • if you write a plugin, enable user customization as described in :help using-<Plug>

Upvotes: 8

Related Questions