I see <Leader> quite often in other people's vimrc files. Like this one.

What is it? What does it do?

  • 1
    possible duplicate of How can I find out what <Leader> is set to? – akshay Feb 16 '15 at 4:17
  • 9
    Akshay: Not a duplicate, that wants to check the value of <leader>, this one wants to know what <leader> means. So that that value can be interpreted. It is the difference between asking "In newton motion what is v?" and "Given an apple falled from a 10m high tree, what is v when it hits the ground?' – Lyndon White Feb 16 '15 at 4:26
  • fair, thanks for the cool analogy :) – akshay Feb 16 '15 at 8:34
  • 3
    So, there is no difference between <Leader> and <leader>, right? – Nikos Alexandris May 3 '15 at 11:31
up vote 23 down vote accepted

Vim is full of various commands, which are assigned to almost all keys on the keyboard. But this causes a problem: Which commands can we use for our own commands, without interfering with existing ones? And at this moment, the <Leader> key comes into play. Think about <Leader>-key like a namespace for any user-defined commands. You can assign any command to a mapping with a leading <Leader> and you can be fully confident that your mapping won't break anything.

Default key for <Leader> is backslash.

To quote :help <Leader>:

To define a mapping which uses the "mapleader" variable, the special string "<Leader>" can be used. It is replaced with the string value of "mapleader". If "mapleader" is not set or empty, a backslash is used instead. Example:

   :map <Leader>A  oanother line<Esc>  

Works like:

   :map \A  oanother line<Esc>  

But after:

   :let mapleader = ","  

It works like:

   :map ,A  oanother line<Esc>

In other words, it lets the first key of mappings (specified in terms of <Leader>) be user defined.

  • 8
    I believe that the rationale behind the <Leader> is that it provides you with a "clean" way to provide custom shortcuts, without overriding existing Vim shortcuts. – Martin Tournoij Feb 16 '15 at 13:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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